feat(weknoracloud): implement credential management and status checks
- Introduced a new WeKnoraCloudSettings component for managing APPID and APPSECRET. - Added functionality to save WeKnoraCloud credentials without automatically creating models. - Implemented credential status checks across various components to provide user feedback on configuration status. - Updated API endpoints to handle credential saving and status retrieval. - Enhanced UI elements to guide users in configuring WeKnoraCloud settings. This update improves the integration of WeKnoraCloud by allowing users to manage their credentials more effectively and receive real-time feedback on their configuration status.
This commit is contained in:
@@ -131,16 +131,22 @@ export interface InitializeWeKnoraCloudRequest {
|
||||
app_secret: string
|
||||
}
|
||||
|
||||
export interface InitializeWeKnoraCloudResult {
|
||||
models: Array<{
|
||||
name: string
|
||||
type: string
|
||||
action: 'created' | 'updated'
|
||||
}>
|
||||
}
|
||||
|
||||
export function initializeWeKnoraCloud(data: InitializeWeKnoraCloudRequest): Promise<InitializeWeKnoraCloudResult> {
|
||||
return post('/api/v1/models/weknoracloud/initialize', data) as Promise<InitializeWeKnoraCloudResult>
|
||||
// 仅保存 WeKnoraCloud 凭证,不自动创建模型
|
||||
export function saveWeKnoraCloudCredentials(data: InitializeWeKnoraCloudRequest): Promise<{ success: boolean; message: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
post('/api/v1/weknoracloud/credentials', data)
|
||||
.then((response: any) => {
|
||||
if (response.success) {
|
||||
resolve(response)
|
||||
} else {
|
||||
reject(new Error(response.message || response.error || '凭证保存失败'))
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('Failed to save WeKnoraCloud credentials:', error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export interface WeKnoraCloudStatusResult {
|
||||
|
||||
@@ -144,27 +144,76 @@
|
||||
</t-select>
|
||||
</div>
|
||||
|
||||
<!-- WeKnoraCloud 提示信息 -->
|
||||
<template v-if="formData.provider === 'weknoracloud'">
|
||||
<!-- 凭证已配置 -->
|
||||
<div v-if="wkcCredentialState === 'configured'" class="weknoracloud-hint weknoracloud-hint--ok">
|
||||
<t-icon name="check-circle-filled" style="font-size: 16px; color: var(--td-success-color); flex-shrink: 0;" />
|
||||
<div>
|
||||
WeKnoraCloud 凭证已配置。
|
||||
支持的模型可参考
|
||||
<a
|
||||
href="https://developers.weixin.qq.com/doc/aispeech/knowledge/atomic_capability/atomic_interface.html"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="weknoracloud-hint-link"
|
||||
>接口文档</a>。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未配置 / 失效 -->
|
||||
<div v-else-if="wkcCredentialState !== 'loading'" class="weknoracloud-hint weknoracloud-hint--warn">
|
||||
<t-icon name="error-circle-filled" style="font-size: 16px; color: #f97316; flex-shrink: 0;" />
|
||||
<div style="flex: 1;">
|
||||
<template v-if="wkcCredentialState === 'expired'">
|
||||
WeKnoraCloud 凭证已失效,请重新配置。
|
||||
</template>
|
||||
<template v-else>
|
||||
尚未配置 WeKnoraCloud 凭证,请先填写 APPID 和 APPSECRET。
|
||||
</template>
|
||||
<div style="margin-top: 8px;">
|
||||
<t-button
|
||||
variant="text"
|
||||
size="small"
|
||||
theme="primary"
|
||||
@click="goToWeKnoraCloudSettings"
|
||||
style="padding: 0; height: auto;"
|
||||
>
|
||||
前往设置中配置
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<div v-else class="weknoracloud-hint">
|
||||
<t-icon name="loading" class="spinning" style="font-size: 16px; color: var(--td-text-color-placeholder); flex-shrink: 0;" />
|
||||
<span>正在检查凭证状态...</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 模型名称 -->
|
||||
<div class="form-item">
|
||||
<label class="form-label required">{{ $t('model.modelName') }}</label>
|
||||
<t-input
|
||||
v-model="formData.modelName"
|
||||
<t-input
|
||||
v-model="formData.modelName"
|
||||
:placeholder="getModelNamePlaceholder()"
|
||||
:disabled="formData.provider === 'weknoracloud' && wkcCredentialState !== 'configured'"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div v-if="formData.provider !== 'weknoracloud'" class="form-item">
|
||||
<label class="form-label required">{{ $t('model.editor.baseUrlLabel') }}</label>
|
||||
<t-input
|
||||
v-model="formData.baseUrl"
|
||||
<t-input
|
||||
v-model="formData.baseUrl"
|
||||
:placeholder="getBaseUrlPlaceholder()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div v-if="formData.provider !== 'weknoracloud'" class="form-item">
|
||||
<label class="form-label">{{ $t('model.editor.apiKeyOptional') }}</label>
|
||||
<t-input
|
||||
v-model="formData.apiKey"
|
||||
<t-input
|
||||
v-model="formData.apiKey"
|
||||
type="password"
|
||||
:placeholder="$t('model.editor.apiKeyPlaceholder')"
|
||||
/>
|
||||
@@ -178,7 +227,7 @@
|
||||
variant="outline"
|
||||
@click="checkRemoteAPI"
|
||||
:loading="checking"
|
||||
:disabled="!formData.modelName || !formData.baseUrl"
|
||||
:disabled="!formData.modelName || (!formData.baseUrl && formData.provider !== 'weknoracloud') || (formData.provider === 'weknoracloud' && wkcCredentialState !== 'configured')"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon
|
||||
@@ -248,7 +297,7 @@
|
||||
<t-button theme="default" variant="outline" @click="handleCancel">
|
||||
{{ $t('common.cancel') }}
|
||||
</t-button>
|
||||
<t-button theme="primary" @click="handleConfirm" :loading="saving">
|
||||
<t-button theme="primary" @click="handleConfirm" :loading="saving" :disabled="formData.provider === 'weknoracloud' && wkcCredentialState !== 'configured'">
|
||||
{{ $t('common.save') }}
|
||||
</t-button>
|
||||
</div>
|
||||
@@ -262,6 +311,7 @@
|
||||
import { ref, watch, computed, onUnmounted, nextTick } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { checkOllamaModels, checkRemoteModel, testEmbeddingModel, checkRerankModel, checkASRModel, listOllamaModels, downloadOllamaModel, getDownloadProgress, checkOllamaStatus, listModelProviders, type OllamaModelInfo, type ModelProviderOption } from '@/api/initialization'
|
||||
import { getWeKnoraCloudStatus } from '@/api/model'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
|
||||
@@ -483,6 +533,34 @@ let downloadInterval: any = null
|
||||
const ollamaServiceStatus = ref<boolean | null>(null)
|
||||
const checkingOllamaStatus = ref(false)
|
||||
|
||||
// WeKnoraCloud 凭证状态
|
||||
const wkcCredentialState = ref<'loading' | 'unconfigured' | 'configured' | 'expired'>('loading')
|
||||
|
||||
const checkWkcCredentialStatus = async () => {
|
||||
wkcCredentialState.value = 'loading'
|
||||
try {
|
||||
const status = await getWeKnoraCloudStatus()
|
||||
if (status.needs_reinit) {
|
||||
wkcCredentialState.value = 'expired'
|
||||
} else if (status.has_models) {
|
||||
wkcCredentialState.value = 'configured'
|
||||
} else {
|
||||
wkcCredentialState.value = 'unconfigured'
|
||||
}
|
||||
} catch {
|
||||
wkcCredentialState.value = 'unconfigured'
|
||||
}
|
||||
}
|
||||
|
||||
const goToWeKnoraCloudSettings = async () => {
|
||||
emit('update:visible', false)
|
||||
if (uiStore.showSettingsModal) {
|
||||
uiStore.closeSettings()
|
||||
await nextTick()
|
||||
}
|
||||
uiStore.openSettings('weknoracloud')
|
||||
}
|
||||
|
||||
const formData = ref<ModelFormData>({
|
||||
id: '',
|
||||
name: '',
|
||||
@@ -625,6 +703,11 @@ watch(() => props.visible, (val) => {
|
||||
if (props.modelType === 'rerank') {
|
||||
formData.value.source = 'remote'
|
||||
}
|
||||
|
||||
// 如果当前 provider 是 WeKnoraCloud,检查凭证状态
|
||||
if (formData.value.provider === 'weknoracloud') {
|
||||
checkWkcCredentialStatus()
|
||||
}
|
||||
} else {
|
||||
// 恢复背景滚动
|
||||
document.body.style.overflow = ''
|
||||
@@ -670,6 +753,10 @@ const handleProviderChange = (value: string) => {
|
||||
remoteAvailable.value = false
|
||||
remoteMessage.value = ''
|
||||
}
|
||||
// WeKnoraCloud: 检查凭证状态
|
||||
if (value === 'weknoracloud') {
|
||||
checkWkcCredentialStatus()
|
||||
}
|
||||
}
|
||||
|
||||
// 监听来源变化,重置校验状态(已合并到下面的 watch)
|
||||
@@ -803,7 +890,7 @@ const checkOllamaDimension = async () => {
|
||||
|
||||
// 检查 Remote API 连接(根据模型类型调用不同的接口)
|
||||
const checkRemoteAPI = async () => {
|
||||
if (!formData.value.modelName || !formData.value.baseUrl) {
|
||||
if (!formData.value.modelName || (!formData.value.baseUrl && formData.value.provider !== 'weknoracloud')) {
|
||||
MessagePlugin.warning(t('model.editor.fillModelAndUrl'))
|
||||
return
|
||||
}
|
||||
@@ -918,8 +1005,8 @@ const handleConfirm = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果是 remote 类型,必须填写 baseUrl
|
||||
if (formData.value.source === 'remote') {
|
||||
// 如果是 remote 类型且非 WeKnoraCloud,必须填写 baseUrl
|
||||
if (formData.value.source === 'remote' && formData.value.provider !== 'weknoracloud') {
|
||||
if (!formData.value.baseUrl || !formData.value.baseUrl.trim()) {
|
||||
MessagePlugin.warning(t('model.editor.remoteBaseUrlRequired'))
|
||||
return
|
||||
@@ -1414,6 +1501,39 @@ const handleOverlayMouseUp = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// WeKnoraCloud 提示信息
|
||||
.weknoracloud-hint {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
margin-bottom: 20px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
line-height: 1.5;
|
||||
|
||||
&--ok {
|
||||
background: var(--td-success-color-light);
|
||||
border: 1px solid var(--td-success-color-focus);
|
||||
}
|
||||
|
||||
&--warn {
|
||||
background: #fff7ed;
|
||||
border: 1px solid #fed7aa;
|
||||
border-left: 3px solid #f97316;
|
||||
}
|
||||
|
||||
.weknoracloud-hint-link {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ollama 模型选择器样式
|
||||
.model-option {
|
||||
display: flex;
|
||||
|
||||
@@ -93,12 +93,14 @@ import { storeToRefs } from 'pinia'
|
||||
const { t } = useI18n()
|
||||
|
||||
function getEngineDisplayName(engineName: string): string {
|
||||
if (engineName === 'weknoracloud') return 'WeKnora Cloud'
|
||||
const key = `kbSettings.parser.engines.${engineName}.name`
|
||||
const translated = t(key)
|
||||
return translated !== key ? translated : engineName
|
||||
}
|
||||
|
||||
function getEngineDisplayDesc(engineName: string, fallback: string): string {
|
||||
if (engineName === 'weknoracloud') return '使用 WeKnora Cloud 进行文档解析'
|
||||
const key = `kbSettings.parser.engines.${engineName}.desc`
|
||||
const translated = t(key)
|
||||
return translated !== key ? translated : fallback
|
||||
|
||||
@@ -18,46 +18,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- WeKnoraCloud 厂商配置 -->
|
||||
<div class="weknoracloud-config-section" style="margin-bottom: 24px;">
|
||||
<div class="category-header" style="margin-bottom: 12px;">
|
||||
<h3 style="margin: 0; font-size: 16px; font-weight: 600;">WeKnoraCloud 厂商配置</h3>
|
||||
</div>
|
||||
<!-- 凭证失效警告 -->
|
||||
<div v-if="weKnoraCloudNeedsReinit" style="margin-bottom: 12px; background: #fff7ed; border: 1px solid #fed7aa; border-left: 3px solid #f97316; border-radius: 6px; padding: 12px 16px; display: flex; align-items: flex-start; gap: 10px;">
|
||||
<t-icon name="error-circle" style="font-size: 16px; color: #f97316; flex-shrink: 0; margin-top: 1px;" />
|
||||
<div style="font-size: 13px; color: #9a3412; line-height: 1.5;">
|
||||
<strong>WeKnoraCloud 凭证已失效</strong><br />
|
||||
{{ weKnoraCloudReinitReason || '服务重启后加密密钥已变更,已保存的凭证无法解密。' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="weknoracloud-config-card" style="background: var(--td-bg-color-container); border: 1px solid var(--td-component-stroke); border-radius: 8px; padding: 20px;">
|
||||
<div style="display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;">
|
||||
<t-form-item label="APPID" style="margin-bottom: 0;">
|
||||
<t-input v-model="weKnoraCloudForm.appId" placeholder="请输入 APPID" style="width: 240px;" />
|
||||
</t-form-item>
|
||||
<t-form-item label="APPSECRET" style="margin-bottom: 0;">
|
||||
<t-input
|
||||
v-model="weKnoraCloudForm.appSecret"
|
||||
type="password"
|
||||
placeholder="请输入 APPSECRET"
|
||||
style="width: 240px;"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-button
|
||||
theme="primary"
|
||||
:loading="weKnoraCloudLoading"
|
||||
@click="handleWeKnoraCloudInit"
|
||||
>
|
||||
保存并初始化
|
||||
</t-button>
|
||||
</div>
|
||||
<p style="color: var(--td-text-color-secondary); font-size: 12px; margin-top: 12px; margin-bottom: 0;">
|
||||
提交后将自动创建或更新三个模型(Chat / Embedding / Rerank)并设为各类型默认
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 对话模型 -->
|
||||
<div class="settings-group model-type-group" data-model-type="chat">
|
||||
<div class="section-subheader">
|
||||
@@ -335,7 +295,7 @@ import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, initializeWeKnoraCloud, getWeKnoraCloudStatus, type ModelConfig } from '@/api/model'
|
||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -344,38 +304,6 @@ const currentModelType = ref<'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'>('
|
||||
const editingModel = ref<any>(null)
|
||||
const loading = ref(true)
|
||||
|
||||
// WeKnoraCloud 配置
|
||||
const weKnoraCloudForm = ref({ appId: '', appSecret: '' })
|
||||
const weKnoraCloudLoading = ref(false)
|
||||
const weKnoraCloudNeedsReinit = ref(false)
|
||||
const weKnoraCloudReinitReason = ref('')
|
||||
|
||||
const handleWeKnoraCloudInit = async () => {
|
||||
if (!weKnoraCloudForm.value.appId || !weKnoraCloudForm.value.appSecret) {
|
||||
MessagePlugin.warning('请填写 APPID 和 APPSECRET')
|
||||
return
|
||||
}
|
||||
weKnoraCloudLoading.value = true
|
||||
try {
|
||||
const result = await initializeWeKnoraCloud({
|
||||
app_id: weKnoraCloudForm.value.appId,
|
||||
app_secret: weKnoraCloudForm.value.appSecret,
|
||||
})
|
||||
const updatedCount = result.models.filter((m: any) => m.action === 'updated').length
|
||||
const createdCount = result.models.filter((m: any) => m.action === 'created').length
|
||||
MessagePlugin.success(`初始化成功:新建 ${createdCount} 个,更新 ${updatedCount} 个模型`)
|
||||
weKnoraCloudForm.value.appId = ''
|
||||
weKnoraCloudForm.value.appSecret = ''
|
||||
weKnoraCloudNeedsReinit.value = false
|
||||
weKnoraCloudReinitReason.value = ''
|
||||
await loadModels()
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || 'WeKnoraCloud 初始化失败')
|
||||
} finally {
|
||||
weKnoraCloudLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 模型列表数据
|
||||
const allModels = ref<ModelConfig[]>([])
|
||||
|
||||
@@ -433,10 +361,6 @@ const loadModels = async () => {
|
||||
// 直接获取所有模型,不分类型
|
||||
const models = await listModels()
|
||||
allModels.value = models
|
||||
// 检查 WeKnoraCloud 凭证状态
|
||||
const status = await getWeKnoraCloudStatus()
|
||||
weKnoraCloudNeedsReinit.value = status.needs_reinit
|
||||
weKnoraCloudReinitReason.value = status.reason || ''
|
||||
} catch (error: any) {
|
||||
console.error('加载模型列表失败:', error)
|
||||
MessagePlugin.error(error.message)
|
||||
|
||||
@@ -93,6 +93,34 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- weknoracloud: 凭证状态 -->
|
||||
<template v-if="engine.Name === 'weknoracloud'">
|
||||
<div v-if="wkcState === 'configured'" class="wkc-status wkc-status--ok">
|
||||
<t-icon name="check-circle" style="font-size: 15px; color: var(--td-success-color); flex-shrink: 0;" />
|
||||
<span>WeKnoraCloud 凭证已配置</span>
|
||||
</div>
|
||||
<div v-else-if="wkcState === 'loading'" class="wkc-status">
|
||||
<t-loading size="small" />
|
||||
<span>检查凭证状态...</span>
|
||||
</div>
|
||||
<div v-else class="wkc-status wkc-status--warn">
|
||||
<t-icon name="error-circle" style="font-size: 15px; color: #f97316; flex-shrink: 0;" />
|
||||
<div style="flex: 1;">
|
||||
<span v-if="wkcState === 'expired'">凭证已失效,请重新配置。</span>
|
||||
<span v-else>尚未配置凭证。</span>
|
||||
<div style="margin-top: 6px;">
|
||||
<t-button
|
||||
variant="text"
|
||||
size="small"
|
||||
theme="primary"
|
||||
@click="goToWkcSettings"
|
||||
style="padding: 0; height: auto;"
|
||||
>前往设置中配置</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="engine.FileTypes && engine.FileTypes.length" class="file-types">
|
||||
<t-tag
|
||||
v-for="ft in engine.FileTypes"
|
||||
@@ -190,8 +218,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import {
|
||||
getParserEngines,
|
||||
getParserEngineConfig,
|
||||
@@ -200,13 +229,16 @@ import {
|
||||
type ParserEngineInfo,
|
||||
type ParserEngineConfig,
|
||||
} from '@/api/system'
|
||||
import { getWeKnoraCloudStatus } from '@/api/model'
|
||||
|
||||
const { t } = useI18n()
|
||||
const uiStore = useUIStore()
|
||||
|
||||
const CONFIGURABLE_ENGINES = new Set(['mineru', 'mineru_cloud'])
|
||||
|
||||
/** 各解析引擎的项目/官方文档地址 */
|
||||
const ENGINE_DOC_LINKS: Record<string, string> = {
|
||||
weknoracloud: 'https://developers.weixin.qq.com/doc/aispeech/knowledge/atomic_capability/atomic_interface.html',
|
||||
markitdown: 'https://github.com/microsoft/markitdown',
|
||||
mineru: 'https://github.com/opendatalab/MinerU',
|
||||
mineru_cloud: 'https://mineru.net/apiManage/docs',
|
||||
@@ -249,10 +281,11 @@ const hasBuiltinEngine = computed(() => engines.value.some(e => e.Name === 'buil
|
||||
/** 固定展示顺序,未列出的引擎排在末尾按名称排序 */
|
||||
const ENGINE_ORDER: Record<string, number> = {
|
||||
builtin: 0,
|
||||
simple: 1,
|
||||
markitdown: 2,
|
||||
mineru: 3,
|
||||
mineru_cloud: 4,
|
||||
weknoracloud: 1,
|
||||
simple: 2,
|
||||
markitdown: 3,
|
||||
mineru: 4,
|
||||
mineru_cloud: 5,
|
||||
}
|
||||
|
||||
const sortedEngines = computed(() => {
|
||||
@@ -277,12 +310,16 @@ function engineDocLabel(_name: string): string {
|
||||
}
|
||||
|
||||
function getEngineDisplayName(engineName: string): string {
|
||||
// WeKnoraCloud 特殊处理
|
||||
if (engineName === 'weknoracloud') return 'WeKnora Cloud'
|
||||
const key = `kbSettings.parser.engines.${engineName}.name`
|
||||
const translated = t(key)
|
||||
return translated !== key ? translated : engineName
|
||||
}
|
||||
|
||||
function getEngineDisplayDesc(engineName: string, fallback: string): string {
|
||||
// WeKnoraCloud 特殊处理
|
||||
if (engineName === 'weknoracloud') return '使用 WeKnora Cloud 进行文档解析,需先在「设置 → WeKnora Cloud」中配置凭证'
|
||||
const key = `kbSettings.parser.engines.${engineName}.desc`
|
||||
const translated = t(key)
|
||||
return translated !== key ? translated : fallback
|
||||
@@ -331,7 +368,7 @@ async function loadConfig() {
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
await Promise.all([loadEngines(), loadConfig()])
|
||||
await Promise.all([loadEngines(), loadConfig(), checkWkcStatus()])
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -389,6 +426,33 @@ async function onSave() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- WeKnoraCloud 凭证状态 ----
|
||||
const wkcState = ref<'loading' | 'unconfigured' | 'configured' | 'expired'>('loading')
|
||||
|
||||
async function checkWkcStatus() {
|
||||
wkcState.value = 'loading'
|
||||
try {
|
||||
const status = await getWeKnoraCloudStatus()
|
||||
if (status.needs_reinit) {
|
||||
wkcState.value = 'expired'
|
||||
} else if (status.has_models) {
|
||||
wkcState.value = 'configured'
|
||||
} else {
|
||||
wkcState.value = 'unconfigured'
|
||||
}
|
||||
} catch {
|
||||
wkcState.value = 'unconfigured'
|
||||
}
|
||||
}
|
||||
|
||||
async function goToWkcSettings() {
|
||||
if (uiStore.showSettingsModal) {
|
||||
uiStore.closeSettings()
|
||||
await nextTick()
|
||||
}
|
||||
uiStore.openSettings('weknoracloud')
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
@@ -596,4 +660,29 @@ onMounted(loadAll)
|
||||
.tag-with-tooltip {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
// ---- WeKnoraCloud 凭证状态 ----
|
||||
.wkc-status {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-bottom: 12px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
|
||||
&--ok {
|
||||
background: var(--td-success-color-light);
|
||||
border: 1px solid var(--td-success-color-focus);
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
&--warn {
|
||||
background: #fff7ed;
|
||||
border: 1px solid #fed7aa;
|
||||
border-left: 3px solid #f97316;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
@click="handleNavClick(item)"
|
||||
>
|
||||
<!-- 网络搜索使用自定义 SVG 图标 -->
|
||||
<svg
|
||||
<svg
|
||||
v-if="item.key === 'websearch'"
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="nav-icon"
|
||||
@@ -42,6 +42,19 @@
|
||||
<line x1="2.94" y1="5.5" x2="15.06" y2="5.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
|
||||
<line x1="2.94" y1="12.5" x2="15.06" y2="12.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
|
||||
</svg>
|
||||
<!-- WeKnora Cloud 使用自定义 W 图标 -->
|
||||
<svg
|
||||
v-else-if="item.key === 'weknoracloud'"
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 18 18"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="nav-icon"
|
||||
>
|
||||
<rect x="1.5" y="1.5" width="15" height="15" rx="3.5" stroke="currentColor" stroke-width="1.2" fill="none"/>
|
||||
<path d="M4.5 5.5L6.5 12.5L9 7.5L11.5 12.5L13.5 5.5" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
||||
</svg>
|
||||
<t-icon v-else :name="item.icon" class="nav-icon" />
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
<t-icon
|
||||
@@ -79,16 +92,21 @@
|
||||
<GeneralSettings />
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
<div v-if="currentSection === 'models'" class="section">
|
||||
<ModelSettings />
|
||||
</div>
|
||||
|
||||
<!-- Ollama 设置 -->
|
||||
<div v-if="currentSection === 'ollama'" class="section">
|
||||
<OllamaSettings />
|
||||
</div>
|
||||
|
||||
<!-- WeKnora Cloud -->
|
||||
<div v-if="currentSection === 'weknoracloud'" class="section">
|
||||
<WeKnoraCloudSettings />
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
<div v-if="currentSection === 'models'" class="section">
|
||||
<ModelSettings />
|
||||
</div>
|
||||
|
||||
<!-- 网络搜索配置 -->
|
||||
<div v-if="currentSection === 'websearch'" class="section">
|
||||
<WebSearchSettings />
|
||||
@@ -153,6 +171,7 @@ import WebSearchSettings from './WebSearchSettings.vue'
|
||||
import ChatHistorySettings from './ChatHistorySettings.vue'
|
||||
import ParserEngineSettings from './ParserEngineSettings.vue'
|
||||
import StorageEngineSettings from './StorageEngineSettings.vue'
|
||||
import WeKnoraCloudSettings from './WeKnoraCloudSettings.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@@ -165,6 +184,8 @@ const expandedMenus = ref<string[]>([])
|
||||
|
||||
const navItems = computed(() => [
|
||||
{ key: 'general', icon: 'setting', label: t('general.title') },
|
||||
{ key: 'ollama', icon: 'server', label: 'Ollama' },
|
||||
{ key: 'weknoracloud', icon: '', label: 'WeKnora Cloud' },
|
||||
{
|
||||
key: 'models',
|
||||
icon: 'control-platform',
|
||||
@@ -176,8 +197,7 @@ const navItems = computed(() => [
|
||||
{ key: 'vllm', label: t('model.vlmModel') }
|
||||
]
|
||||
},
|
||||
{ key: 'ollama', icon: 'server', label: 'Ollama' },
|
||||
{ key: 'websearch', icon: 'search', label: t('settings.webSearchConfig') },
|
||||
{ key: 'websearch', icon: 'search', label: t('settings.webSearchConfig') },
|
||||
{ key: 'chathistory', icon: 'chat', label: t('chatHistorySettings.title') },
|
||||
{
|
||||
key: 'parser',
|
||||
@@ -185,6 +205,7 @@ const navItems = computed(() => [
|
||||
label: t('settings.parserEngine'),
|
||||
children: [
|
||||
{ key: 'builtin', label: 'Builtin (DocReader)' },
|
||||
{ key: 'weknoracloud', label: 'WeKnora Cloud' },
|
||||
{ key: 'simple', label: 'Simple' },
|
||||
{ key: 'markitdown', label: 'Markitdown' },
|
||||
{ key: 'mineru', label: 'MinerU' },
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
<template>
|
||||
<div class="weknoracloud-settings">
|
||||
<div class="section-header">
|
||||
<h2>WeKnora Cloud</h2>
|
||||
<p class="section-description">
|
||||
配置 WeKnora Cloud 的 APPID 和 APPSECRET 凭证。配置完成后,可在模型管理中添加模型时选择 WeKnoraCloud 作为厂商。
|
||||
</p>
|
||||
<a
|
||||
class="doc-link"
|
||||
href="https://developers.weixin.qq.com/doc/aispeech/knowledge/atomic_capability/atomic_interface.html"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<t-icon name="link" style="font-size: 14px;" />
|
||||
查看文档
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 状态区域 -->
|
||||
<!-- 未配置 -->
|
||||
<div v-if="credentialState === 'unconfigured'" class="credential-status unconfigured">
|
||||
<t-icon name="info-circle" style="font-size: 16px; flex-shrink: 0;" />
|
||||
<span>尚未配置凭证,请填写 APPID 和 APPSECRET</span>
|
||||
</div>
|
||||
|
||||
<!-- 凭证失效 -->
|
||||
<div v-else-if="credentialState === 'expired'" class="credential-warning">
|
||||
<t-icon name="error-circle" style="font-size: 16px; color: #f97316; flex-shrink: 0; margin-top: 1px;" />
|
||||
<div class="warning-text">
|
||||
<strong>WeKnora Cloud凭证已失效</strong><br />
|
||||
{{ reinitReason || '服务重启后加密密钥已变更,已保存的凭证无法解密。请重新填写凭证。' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 已配置正常 -->
|
||||
<div v-else-if="credentialState === 'configured'" class="credential-status success">
|
||||
<t-icon name="check-circle" style="font-size: 16px; color: var(--td-success-color); flex-shrink: 0;" />
|
||||
<span class="status-text">凭证已配置,状态正常</span>
|
||||
<t-button
|
||||
v-if="!formExpanded"
|
||||
variant="text"
|
||||
size="small"
|
||||
theme="primary"
|
||||
@click="formExpanded = true"
|
||||
>
|
||||
重新配置
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<!-- 配置表单(折叠控制) -->
|
||||
<div v-if="formExpanded" class="settings-group">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label class="setting-label">APPID</label>
|
||||
<p class="setting-desc">WeKnora Cloud的应用 ID</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="form.appId"
|
||||
placeholder="请输入 APPID"
|
||||
autocomplete="off"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label class="setting-label">APPSECRET</label>
|
||||
<p class="setting-desc">WeKnora Cloud的应用密钥</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="form.appSecret"
|
||||
type="password"
|
||||
placeholder="请输入 APPSECRET"
|
||||
autocomplete="new-password"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row action-row">
|
||||
<div class="setting-info">
|
||||
<p class="setting-desc">保存后将验证服务可达性并加密存储凭证</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-button
|
||||
theme="primary"
|
||||
:loading="saving"
|
||||
:disabled="!form.appId || !form.appSecret"
|
||||
@click="handleSave"
|
||||
>
|
||||
保存凭证
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 使用说明 -->
|
||||
<div class="usage-hint">
|
||||
<p class="hint-title">使用说明</p>
|
||||
<p class="hint-text">
|
||||
1. 在此页面填写并保存 APPID 和 APPSECRET<br />
|
||||
2. 前往「模型管理」添加模型,选择 Remote API 来源<br />
|
||||
3. 在厂商下拉中选择「WeKnoraCloud」<br />
|
||||
4. 填写模型名称后保存即可(Base URL 和认证信息会自动配置)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { saveWeKnoraCloudCredentials, getWeKnoraCloudStatus } from '@/api/model'
|
||||
|
||||
const form = ref({ appId: '', appSecret: '' })
|
||||
const saving = ref(false)
|
||||
const needsReinit = ref(false)
|
||||
const reinitReason = ref('')
|
||||
const hasCredentials = ref(false)
|
||||
const formExpanded = ref(true)
|
||||
|
||||
// 三态:unconfigured / configured / expired
|
||||
const credentialState = computed(() => {
|
||||
if (needsReinit.value) return 'expired'
|
||||
if (hasCredentials.value) return 'configured'
|
||||
return 'unconfigured'
|
||||
})
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!form.value.appId || !form.value.appSecret) {
|
||||
MessagePlugin.warning('请填写 APPID 和 APPSECRET')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await saveWeKnoraCloudCredentials({
|
||||
app_id: form.value.appId,
|
||||
app_secret: form.value.appSecret,
|
||||
})
|
||||
MessagePlugin.success('凭证保存成功')
|
||||
form.value.appId = ''
|
||||
form.value.appSecret = ''
|
||||
needsReinit.value = false
|
||||
reinitReason.value = ''
|
||||
hasCredentials.value = true
|
||||
formExpanded.value = false
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || '凭证保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const checkStatus = async () => {
|
||||
try {
|
||||
const status = await getWeKnoraCloudStatus()
|
||||
needsReinit.value = status.needs_reinit
|
||||
reinitReason.value = status.reason || ''
|
||||
hasCredentials.value = status.has_models && !status.needs_reinit
|
||||
// 已配置且未失效时默认收起表单
|
||||
if (hasCredentials.value) {
|
||||
formExpanded.value = false
|
||||
}
|
||||
} catch {
|
||||
// 静默失败
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
checkStatus()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.weknoracloud-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 24px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0 0 10px 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 13px;
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.credential-warning {
|
||||
margin-bottom: 20px;
|
||||
background: #fff7ed;
|
||||
border: 1px solid #fed7aa;
|
||||
border-left: 3px solid #f97316;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
|
||||
.warning-text {
|
||||
font-size: 13px;
|
||||
color: #9a3412;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.credential-status {
|
||||
margin-bottom: 20px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
|
||||
&.unconfigured {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&.success {
|
||||
background: var(--td-success-color-light);
|
||||
border: 1px solid var(--td-success-color-focus);
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
.status-text {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&.action-row {
|
||||
padding-top: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.setting-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.usage-hint {
|
||||
padding: 14px 16px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
|
||||
.hint-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.hint-text {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
line-height: 1.8;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user