feat(web-search): refactor web search provider
- Updated relevant files to include provider registration, implementation, and metadata. - Enhanced frontend components to support provider management and configuration. - Added localization for new provider settings and messages. - Implemented backend repository methods for CRUD operations on web search providers.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
// WebSearchProviderEntity represents a configured web search provider instance
|
||||
export interface WebSearchProviderEntity {
|
||||
id?: string
|
||||
tenant_id?: number
|
||||
name: string
|
||||
provider: 'bing' | 'google' | 'duckduckgo' | 'tavily'
|
||||
description?: string
|
||||
parameters: {
|
||||
api_key?: string
|
||||
engine_id?: string
|
||||
extra_config?: Record<string, string>
|
||||
}
|
||||
is_default?: boolean
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
// WebSearchProviderTypeInfo describes metadata for a provider type
|
||||
export interface WebSearchProviderTypeInfo {
|
||||
id: string
|
||||
name: string
|
||||
requires_api_key: boolean
|
||||
requires_engine_id?: boolean
|
||||
description?: string
|
||||
docs_url?: string
|
||||
}
|
||||
|
||||
// Create a new web search provider
|
||||
export function createWebSearchProvider(data: Partial<WebSearchProviderEntity>) {
|
||||
return post('/api/v1/web-search-providers', data)
|
||||
}
|
||||
|
||||
// List all web search providers for the current tenant
|
||||
export function listWebSearchProviders() {
|
||||
return get('/api/v1/web-search-providers')
|
||||
}
|
||||
|
||||
// Get a single web search provider by ID
|
||||
export function getWebSearchProvider(id: string) {
|
||||
return get(`/api/v1/web-search-providers/${id}`)
|
||||
}
|
||||
|
||||
// Update an existing web search provider
|
||||
export function updateWebSearchProvider(id: string, data: Partial<WebSearchProviderEntity>) {
|
||||
return put(`/api/v1/web-search-providers/${id}`, data)
|
||||
}
|
||||
|
||||
// Delete a web search provider
|
||||
export function deleteWebSearchProvider(id: string) {
|
||||
return del(`/api/v1/web-search-providers/${id}`)
|
||||
}
|
||||
|
||||
// Get available provider types (for dynamic form rendering)
|
||||
export function listWebSearchProviderTypes(): Promise<WebSearchProviderTypeInfo[]> {
|
||||
return get('/api/v1/web-search-providers/types').then((res: any) => {
|
||||
if (res.success && res.data) {
|
||||
return res.data
|
||||
}
|
||||
return []
|
||||
})
|
||||
}
|
||||
|
||||
// Test a web search provider connection.
|
||||
// If id is provided, tests the existing saved provider.
|
||||
// If data is provided, tests with raw credentials (no persistence).
|
||||
export function testWebSearchProvider(id?: string, data?: { provider: string; parameters: any }): Promise<any> {
|
||||
if (id) {
|
||||
return post(`/api/v1/web-search-providers/${id}/test`, {})
|
||||
}
|
||||
return post('/api/v1/web-search-providers/test', data || {})
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { get, put } from '@/utils/request'
|
||||
|
||||
// WebSearchProviderConfig represents information about a web search provider
|
||||
// WebSearchProviderConfig represents information about a web search provider type
|
||||
// Deprecated: Use WebSearchProviderTypeInfo from web-search-provider.ts instead
|
||||
export interface WebSearchProviderConfig {
|
||||
id: string
|
||||
name: string
|
||||
@@ -12,7 +13,10 @@ export interface WebSearchProviderConfig {
|
||||
|
||||
// WebSearchConfig represents the web search configuration for a tenant
|
||||
export interface WebSearchConfig {
|
||||
provider: string
|
||||
// New: references a WebSearchProviderEntity by ID
|
||||
default_provider_id?: string
|
||||
// Deprecated: kept for backward compatibility
|
||||
provider?: string
|
||||
api_key?: string
|
||||
max_results: number
|
||||
include_date: boolean
|
||||
@@ -24,7 +28,7 @@ export interface WebSearchConfig {
|
||||
document_fragments?: number
|
||||
}
|
||||
|
||||
// Get web search providers
|
||||
// Get web search provider types (available engines)
|
||||
export function getWebSearchProviders() {
|
||||
return get('/api/v1/web-search/providers')
|
||||
}
|
||||
@@ -38,4 +42,3 @@ export function getTenantWebSearchConfig() {
|
||||
export function updateTenantWebSearchConfig(config: WebSearchConfig) {
|
||||
return put('/api/v1/tenants/kv/web-search-config', config)
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,11 @@ export default {
|
||||
suggestedPrompts: 'Suggested Prompts',
|
||||
mode: 'Running Mode',
|
||||
webSearch: 'Web Search',
|
||||
webSearchProvider: 'Search Engine',
|
||||
webSearchProviderPlaceholder: 'Use default search engine',
|
||||
webSearchMaxResults: 'Max Search Results',
|
||||
webFetchEnabled: 'Auto-Fetch Page Content',
|
||||
webFetchTopN: 'Pages to Fetch',
|
||||
knowledgeBases: 'Knowledge Bases',
|
||||
allKnowledgeBases: 'All Knowledge Bases',
|
||||
allKnowledgeBasesDesc: 'Agent can access all knowledge bases',
|
||||
@@ -699,6 +703,34 @@ export default {
|
||||
webSearchSettings: {
|
||||
title: 'Web Search Configuration',
|
||||
description: 'Configure web search so answers can include up-to-date information from the internet.',
|
||||
// Provider entity management
|
||||
providersTitle: 'Search Engine Providers',
|
||||
addProvider: 'Add Provider',
|
||||
editProvider: 'Edit Provider',
|
||||
noProviders: 'No search engine providers configured. Click "Add Provider" to get started.',
|
||||
deleteConfirm: 'Are you sure you want to delete this provider?',
|
||||
default: 'Default',
|
||||
providerNameLabel: 'Name',
|
||||
providerNamePlaceholder: 'e.g., Production Bing Search',
|
||||
providerTypeLabel: 'Provider Type',
|
||||
providerDescLabel: 'Notes',
|
||||
providerDescPlaceholder: 'Optional, e.g., for testing',
|
||||
engineIdLabel: 'Engine ID',
|
||||
setAsDefault: 'Set as default',
|
||||
testConnection: 'Test Connection',
|
||||
testing: 'Testing...',
|
||||
free: 'Free',
|
||||
viewDocs: 'View docs for API key',
|
||||
apiKeyUnchanged: 'Leave empty to keep current key',
|
||||
noDescription: "No description provided",
|
||||
noProvidersDesc: "Add a web search provider to enable your agents to retrieve real-time information from the internet.",
|
||||
basicInfo: "Basic Information",
|
||||
credentials: "Credentials",
|
||||
setAsDefaultDesc: "This provider will be used by default when an agent doesn't specify one",
|
||||
// Search behavior
|
||||
searchBehaviorTitle: 'Search Behavior',
|
||||
defaultProviderLabel: 'Default Provider',
|
||||
defaultProviderDescription: 'Select the default search provider for agents that do not specify their own.',
|
||||
providerLabel: 'Search Provider',
|
||||
providerDescription: 'Choose the search engine service used for web search',
|
||||
providerPlaceholder: 'Select a search engine...',
|
||||
@@ -722,7 +754,12 @@ export default {
|
||||
toasts: {
|
||||
loadProvidersFailed: 'Failed to load search providers: {message}',
|
||||
saveSuccess: 'Web search configuration saved',
|
||||
saveFailed: 'Failed to save configuration: {message}'
|
||||
saveFailed: 'Failed to save configuration: {message}',
|
||||
providerCreated: 'Search provider created',
|
||||
providerUpdated: 'Search provider updated',
|
||||
providerDeleted: 'Search provider deleted',
|
||||
testSuccess: 'Connection test succeeded',
|
||||
testFailed: 'Connection test failed',
|
||||
}
|
||||
},
|
||||
chatHistorySettings: {
|
||||
@@ -3178,7 +3215,10 @@ export default {
|
||||
maxIterations: 'Maximum reasoning steps when the Agent executes tasks',
|
||||
kbScope: 'Select the scope of knowledge bases accessible to the agent',
|
||||
webSearch: 'When enabled, the agent can search the internet for information',
|
||||
webSearchProvider: 'Specify a search engine for this agent. Leave empty to use the default.',
|
||||
webSearchMaxResults: 'Maximum number of results returned per search',
|
||||
webFetchEnabled: 'After reranking, auto-fetch full page content from top web results for better answers',
|
||||
webFetchTopN: 'Maximum number of web pages to fetch after reranking',
|
||||
retrievalSection: 'Configure knowledge base retrieval and ranking parameters',
|
||||
queryExpansion: 'Automatically expand query terms to improve recall',
|
||||
embeddingTopK: 'Maximum number of results from vector retrieval',
|
||||
|
||||
@@ -550,6 +550,31 @@ export default {
|
||||
title: "웹 검색 설정",
|
||||
description:
|
||||
"웹 검색 기능을 구성하여 질문에 답변할 때 인터넷에서 실시간 정보를 가져와 지식베이스 내용을 보완합니다",
|
||||
providersTitle: "검색 엔진 프로바이더 설정",
|
||||
addProvider: "프로바이더 추가",
|
||||
editProvider: "프로바이더 편집",
|
||||
noProviders: "검색 엔진 프로바이더가 설정되지 않았습니다. \"프로바이더 추가\"를 클릭하여 시작하세요.",
|
||||
deleteConfirm: "이 프로바이더를 삭제하시겠습니까?",
|
||||
default: "기본",
|
||||
providerNameLabel: "이름",
|
||||
providerNamePlaceholder: "예: 프로덕션 Bing 검색",
|
||||
providerTypeLabel: "프로바이더 유형",
|
||||
providerDescLabel: "설명",
|
||||
engineIdLabel: "엔진 ID",
|
||||
setAsDefault: "기본으로 설정",
|
||||
free: "무료",
|
||||
viewDocs: "문서에서 API 키 확인",
|
||||
apiKeyUnchanged: "현재 키를 유지하려면 비워두세요",
|
||||
testConnection: "연결 테스트",
|
||||
testing: "테스트 중...",
|
||||
noDescription: "설명 없음",
|
||||
noProvidersDesc: "웹 검색 프로바이더를 추가하여 에이전트가 인터넷에서 실시간 정보를 가져올 수 있도록 합니다.",
|
||||
basicInfo: "기본 정보",
|
||||
credentials: "자격 증명",
|
||||
setAsDefaultDesc: "에이전트가 검색 엔진을 지정하지 않은 경우 이 프로바이더가 기본적으로 사용됩니다",
|
||||
searchBehaviorTitle: "검색 동작 설정",
|
||||
defaultProviderLabel: "기본 프로바이더",
|
||||
defaultProviderDescription: "자체 프로바이더를 지정하지 않은 에이전트의 기본 검색 프로바이더를 선택합니다",
|
||||
providerLabel: "검색 엔진 프로바이더",
|
||||
providerDescription: "웹 검색에 사용할 검색 엔진 서비스 선택",
|
||||
providerPlaceholder: "검색 엔진 선택...",
|
||||
@@ -575,6 +600,9 @@ export default {
|
||||
loadProvidersFailed: "검색 엔진 목록 로드 실패: {message}",
|
||||
saveSuccess: "웹 검색 설정이 저장되었습니다",
|
||||
saveFailed: "설정 저장 실패: {message}",
|
||||
providerCreated: "검색 엔진 프로바이더가 생성되었습니다",
|
||||
providerUpdated: "검색 엔진 프로바이더가 업데이트되었습니다",
|
||||
providerDeleted: "검색 엔진 프로바이더가 삭제되었습니다",
|
||||
},
|
||||
},
|
||||
chatHistorySettings: {
|
||||
|
||||
@@ -672,6 +672,31 @@ export default {
|
||||
webSearchSettings: {
|
||||
title: 'Настройки веб-поиска',
|
||||
description: 'Настройте веб-поиск, чтобы ответы могли включать актуальную информацию из интернета.',
|
||||
providersTitle: 'Поисковые провайдеры',
|
||||
addProvider: 'Добавить провайдер',
|
||||
editProvider: 'Редактировать провайдер',
|
||||
noProviders: 'Поисковые провайдеры не настроены. Нажмите «Добавить провайдер», чтобы начать.',
|
||||
deleteConfirm: 'Вы уверены, что хотите удалить этот провайдер?',
|
||||
default: 'По умолчанию',
|
||||
providerNameLabel: 'Название',
|
||||
providerNamePlaceholder: 'Напр., Продакшн Bing Поиск',
|
||||
providerTypeLabel: 'Тип провайдера',
|
||||
providerDescLabel: 'Описание',
|
||||
engineIdLabel: 'ID движка',
|
||||
setAsDefault: 'Установить по умолчанию',
|
||||
free: 'Бесплатно',
|
||||
viewDocs: 'Документация для получения ключа',
|
||||
apiKeyUnchanged: 'Оставьте пустым, чтобы сохранить текущий ключ',
|
||||
testConnection: 'Проверить соединение',
|
||||
testing: 'Тестирование...',
|
||||
noDescription: "Нет описания",
|
||||
noProvidersDesc: "Добавьте провайдера веб-поиска, чтобы позволить вашим агентам получать информацию из Интернета в реальном времени.",
|
||||
basicInfo: "Основная информация",
|
||||
credentials: "Учетные данные",
|
||||
setAsDefaultDesc: "Этот провайдер будет использоваться по умолчанию, если агент не укажет свой",
|
||||
searchBehaviorTitle: 'Поведение поиска',
|
||||
defaultProviderLabel: 'Провайдер по умолчанию',
|
||||
defaultProviderDescription: 'Выберите провайдер поиска по умолчанию для агентов, не указавших собственный.',
|
||||
providerLabel: 'Провайдер поиска',
|
||||
providerDescription: 'Выберите поисковый сервис, используемый для веб-поиска',
|
||||
providerPlaceholder: 'Выберите поисковую систему...',
|
||||
@@ -697,7 +722,10 @@ export default {
|
||||
toasts: {
|
||||
loadProvidersFailed: 'Не удалось загрузить список поисковых провайдеров: {message}',
|
||||
saveSuccess: 'Настройки веб-поиска сохранены',
|
||||
saveFailed: 'Не удалось сохранить настройки: {message}'
|
||||
saveFailed: 'Не удалось сохранить настройки: {message}',
|
||||
providerCreated: 'Поисковый провайдер создан',
|
||||
providerUpdated: 'Поисковый провайдер обновлён',
|
||||
providerDeleted: 'Поисковый провайдер удалён',
|
||||
}
|
||||
},
|
||||
chatHistorySettings: {
|
||||
|
||||
@@ -558,6 +558,34 @@ export default {
|
||||
title: "网络搜索配置",
|
||||
description:
|
||||
"配置网络搜索功能,在回答问题时可以从互联网获取实时信息补充知识库内容",
|
||||
// Provider entity management
|
||||
providersTitle: "搜索引擎配置",
|
||||
addProvider: "添加搜索引擎",
|
||||
editProvider: "编辑搜索引擎",
|
||||
noProviders: "暂无搜索引擎配置,点击「添加搜索引擎」开始配置。",
|
||||
deleteConfirm: "确定要删除此搜索引擎配置吗?",
|
||||
default: "默认",
|
||||
providerNameLabel: "名称",
|
||||
providerNamePlaceholder: "例如:生产环境 Bing 搜索",
|
||||
providerTypeLabel: "引擎类型",
|
||||
providerDescLabel: "备注",
|
||||
providerDescPlaceholder: "可选,如:测试环境用",
|
||||
engineIdLabel: "搜索引擎 ID",
|
||||
setAsDefault: "设为默认",
|
||||
testConnection: "测试连接",
|
||||
testing: "测试中...",
|
||||
free: "免费",
|
||||
viewDocs: "查看文档获取密钥",
|
||||
apiKeyUnchanged: "留空保持当前密钥不变",
|
||||
noDescription: "暂无描述",
|
||||
noProvidersDesc: "添加一个网络搜索引擎,为您的智能体提供实时的互联网信息检索能力。",
|
||||
basicInfo: "基础信息",
|
||||
credentials: "凭证信息",
|
||||
setAsDefaultDesc: "当智能体没有指定特定的搜索引擎时,将默认使用此配置",
|
||||
// Search behavior
|
||||
searchBehaviorTitle: "搜索行为配置",
|
||||
defaultProviderLabel: "默认搜索引擎",
|
||||
defaultProviderDescription: "为未指定搜索引擎的智能体选择默认使用的搜索引擎",
|
||||
providerLabel: "搜索引擎提供商",
|
||||
providerDescription: "选择用于网络搜索的搜索引擎服务",
|
||||
providerPlaceholder: "选择搜索引擎...",
|
||||
@@ -583,6 +611,11 @@ export default {
|
||||
loadProvidersFailed: "加载搜索引擎列表失败: {message}",
|
||||
saveSuccess: "网络搜索配置已保存",
|
||||
saveFailed: "保存配置失败: {message}",
|
||||
providerCreated: "搜索引擎配置已创建",
|
||||
providerUpdated: "搜索引擎配置已更新",
|
||||
providerDeleted: "搜索引擎配置已删除",
|
||||
testSuccess: "连接测试成功",
|
||||
testFailed: "连接测试失败",
|
||||
},
|
||||
},
|
||||
chatHistorySettings: {
|
||||
@@ -1155,7 +1188,11 @@ export default {
|
||||
suggestedPrompts: "推荐问题",
|
||||
mode: "运行模式",
|
||||
webSearch: "网络搜索",
|
||||
webSearchProvider: "搜索引擎",
|
||||
webSearchProviderPlaceholder: "使用默认搜索引擎",
|
||||
webSearchMaxResults: "最大搜索结果数",
|
||||
webFetchEnabled: "自动抓取页面内容",
|
||||
webFetchTopN: "抓取页面数",
|
||||
knowledgeBases: "关联知识库",
|
||||
allKnowledgeBases: "全部知识库",
|
||||
allKnowledgeBasesDesc: "智能体可访问所有知识库",
|
||||
@@ -3176,7 +3213,10 @@ export default {
|
||||
maxIterations: "Agent 执行任务时的最大推理步骤数",
|
||||
kbScope: "选择智能体可访问的知识库范围",
|
||||
webSearch: "启用后智能体可以搜索互联网获取信息",
|
||||
webSearchProvider: "为此智能体指定搜索引擎,留空则使用默认搜索引擎",
|
||||
webSearchMaxResults: "每次搜索返回的最大结果数量",
|
||||
webFetchEnabled: "Rerank 后自动抓取排名靠前的网页完整内容,提升回答质量",
|
||||
webFetchTopN: "Rerank 后最多抓取几个网页的完整内容",
|
||||
retrievalSection: "配置知识库检索和排序的参数",
|
||||
queryExpansion: "自动扩展查询词以提高召回率",
|
||||
embeddingTopK: "向量检索返回的最大结果数量",
|
||||
|
||||
@@ -914,6 +914,32 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网络搜索最大结果数 -->
|
||||
<div v-if="formData.config.web_search_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agent.editor.webSearchProvider') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.desc.webSearchProvider') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="formData.config.web_search_provider_id"
|
||||
clearable
|
||||
:placeholder="$t('agent.editor.webSearchProviderPlaceholder')"
|
||||
style="width: 240px;"
|
||||
>
|
||||
<t-option
|
||||
v-for="p in webSearchProviderList"
|
||||
:key="p.id"
|
||||
:value="p.id"
|
||||
:label="p.name"
|
||||
>
|
||||
<span>{{ p.name }}</span>
|
||||
<t-tag v-if="p.is_default" theme="primary" size="small" style="margin-left: 6px;">{{ $t('common.default') }}</t-tag>
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网络搜索最大结果数 -->
|
||||
<div v-if="formData.config.web_search_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -927,6 +953,31 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 自动抓取页面内容 -->
|
||||
<div v-if="formData.config.web_search_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agent.editor.webFetchEnabled') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.desc.webFetchEnabled') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch v-model="formData.config.web_fetch_enabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 抓取页面数 -->
|
||||
<div v-if="formData.config.web_search_enabled && formData.config.web_fetch_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agent.editor.webFetchTopN') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.desc.webFetchTopN') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-wrapper">
|
||||
<t-slider v-model="formData.config.web_fetch_top_n" :min="1" :max="10" />
|
||||
<span class="slider-value">{{ formData.config.web_fetch_top_n }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1164,6 +1215,7 @@ import { listModels, type ModelConfig } from '@/api/model';
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base';
|
||||
import { listMCPServices, type MCPService } from '@/api/mcp-service';
|
||||
import { listSkills, type SkillInfo } from '@/api/skill';
|
||||
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
|
||||
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, type StorageEngineStatusItem, type PromptTemplate } from '@/api/system';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
@@ -1195,6 +1247,7 @@ const saving = ref(false);
|
||||
const allModels = ref<ModelConfig[]>([]);
|
||||
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number; shared?: boolean; orgName?: string }[]>([]);
|
||||
const mcpOptions = ref<{ label: string; value: string }[]>([]);
|
||||
const webSearchProviderList = ref<WebSearchProviderEntity[]>([]);
|
||||
const skillOptions = ref<{ name: string; description: string }[]>([]);
|
||||
// 是否允许启用 Skills(取决于后端沙箱是否启用,disabled 时为 false;未请求前为 false 避免闪显)
|
||||
const skillsAvailable = ref(false);
|
||||
@@ -1919,6 +1972,16 @@ const loadDependencies = async () => {
|
||||
console.warn('Failed to load storage engine status', e);
|
||||
}
|
||||
|
||||
// 加载网络搜索引擎配置列表
|
||||
try {
|
||||
const wsRes: any = await listWebSearchProviders();
|
||||
if (wsRes?.data && Array.isArray(wsRes.data)) {
|
||||
webSearchProviderList.value = wsRes.data;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to load web search providers', e);
|
||||
}
|
||||
|
||||
// 加载占位符定义(从统一 API)
|
||||
try {
|
||||
const placeholdersRes = await getPlaceholders();
|
||||
|
||||
@@ -6,380 +6,325 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- 搜索引擎提供商 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.providerLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.providerDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localProvider"
|
||||
:loading="loadingProviders"
|
||||
filterable
|
||||
:placeholder="t('webSearchSettings.providerPlaceholder')"
|
||||
@change="handleProviderChange"
|
||||
@focus="loadProviders"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<t-option
|
||||
v-for="provider in providers"
|
||||
:key="provider.id"
|
||||
:value="provider.id"
|
||||
:label="provider.name"
|
||||
>
|
||||
<div class="provider-option-wrapper">
|
||||
<div class="provider-option">
|
||||
<span class="provider-name">{{ provider.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
<div class="section-subheader">
|
||||
<h3>{{ t('webSearchSettings.providersTitle') }}</h3>
|
||||
<t-button theme="primary" size="small" @click="openAddDialog">
|
||||
<template #icon><add-icon /></template>
|
||||
{{ t('webSearchSettings.addProvider') }}
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<!-- API 密钥 -->
|
||||
<div v-if="selectedProvider && selectedProvider.requires_api_key" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.apiKeyLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.apiKeyDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localAPIKey"
|
||||
type="password"
|
||||
:placeholder="t('webSearchSettings.apiKeyPlaceholder')"
|
||||
@change="handleAPIKeyChange"
|
||||
style="width: 400px;"
|
||||
:show-password="true"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最大结果数 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.maxResultsLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.maxResultsDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-with-value">
|
||||
<t-slider
|
||||
v-model="localMaxResults"
|
||||
:min="1"
|
||||
:max="50"
|
||||
:step="1"
|
||||
:marks="{ 1: '1', 10: '10', 20: '20', 30: '30', 40: '40', 50: '50' }"
|
||||
@change="handleMaxResultsChange"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localMaxResults }}</span>
|
||||
<!-- Provider List -->
|
||||
<div v-if="providerEntities.length > 0" class="provider-list">
|
||||
<div v-for="entity in providerEntities" :key="entity.id" class="provider-item">
|
||||
<div class="item-info">
|
||||
<div class="item-header">
|
||||
<span class="item-name">{{ entity.name }}</span>
|
||||
<t-tag v-if="entity.is_default" theme="primary" size="small" variant="light">
|
||||
{{ t('webSearchSettings.default') }}
|
||||
</t-tag>
|
||||
<t-tag size="small" variant="outline">{{ entity.provider }}</t-tag>
|
||||
</div>
|
||||
<div class="item-desc">{{ entity.description || t('webSearchSettings.noDescription') }}</div>
|
||||
</div>
|
||||
<div class="item-actions">
|
||||
<t-button theme="default" variant="text" size="small" @click="testExistingConnection(entity)" :loading="testingId === entity.id">
|
||||
{{ t('webSearchSettings.testConnection') }}
|
||||
</t-button>
|
||||
<t-button theme="primary" variant="text" size="small" @click="editProvider(entity)">
|
||||
{{ t('common.edit') }}
|
||||
</t-button>
|
||||
<t-popconfirm :content="t('webSearchSettings.deleteConfirm')" @confirm="deleteProvider(entity.id!)">
|
||||
<t-button theme="danger" variant="text" size="small">
|
||||
{{ t('common.delete') }}
|
||||
</t-button>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 包含日期 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.includeDateLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.includeDateDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localIncludeDate"
|
||||
@change="handleIncludeDateChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 压缩方法 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.compressionLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.compressionDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localCompressionMethod"
|
||||
@change="handleCompressionMethodChange"
|
||||
style="width: 280px;"
|
||||
:placeholder="t('webSearchSettings.compressionLabel')"
|
||||
>
|
||||
<t-option value="none" :label="t('webSearchSettings.compressionNone')">
|
||||
{{ t('webSearchSettings.compressionNone') }}
|
||||
</t-option>
|
||||
<t-option value="llm_summary" :label="t('webSearchSettings.compressionSummary')">
|
||||
{{ t('webSearchSettings.compressionSummary') }}
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 黑名单 -->
|
||||
<div class="setting-row vertical">
|
||||
<div class="setting-info">
|
||||
<label>{{ t('webSearchSettings.blacklistLabel') }}</label>
|
||||
<p class="desc">{{ t('webSearchSettings.blacklistDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-textarea
|
||||
v-model="localBlacklistText"
|
||||
:placeholder="t('webSearchSettings.blacklistPlaceholder')"
|
||||
:autosize="{ minRows: 4, maxRows: 8 }"
|
||||
@change="handleBlacklistChange"
|
||||
style="width: 500px;"
|
||||
/>
|
||||
</div>
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-providers">
|
||||
<p>{{ t('webSearchSettings.noProvidersDesc') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add/Edit Dialog -->
|
||||
<t-dialog
|
||||
v-model:visible="showAddProviderDialog"
|
||||
:header="editingProvider ? t('webSearchSettings.editProvider') : t('webSearchSettings.addProvider')"
|
||||
width="520px"
|
||||
:footer="false"
|
||||
destroy-on-close
|
||||
>
|
||||
<div class="dialog-form-container">
|
||||
<t-form :data="providerForm" label-align="top" @submit="saveProvider" class="provider-form">
|
||||
<t-form-item :label="t('webSearchSettings.providerTypeLabel')" name="provider">
|
||||
<t-select v-model="providerForm.provider" :disabled="!!editingProvider" @change="onProviderTypeChange">
|
||||
<t-option v-for="pt in providerTypes" :key="pt.id" :value="pt.id" :label="pt.name">
|
||||
<div class="provider-option">
|
||||
<span>{{ pt.name }}</span>
|
||||
<t-tag v-if="pt.free" theme="success" size="small" variant="light">{{ t('webSearchSettings.free') }}</t-tag>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
|
||||
<t-form-item :label="t('webSearchSettings.providerNameLabel')" name="name">
|
||||
<t-input v-model="providerForm.name" :placeholder="selectedProviderType?.name || t('webSearchSettings.providerNamePlaceholder')" />
|
||||
</t-form-item>
|
||||
|
||||
<t-form-item :label="t('webSearchSettings.providerDescLabel')" name="description">
|
||||
<t-input v-model="providerForm.description" :placeholder="t('webSearchSettings.providerDescPlaceholder')" />
|
||||
</t-form-item>
|
||||
|
||||
<template v-if="selectedProviderType?.requires_api_key || selectedProviderType?.requires_engine_id">
|
||||
<div class="form-divider"></div>
|
||||
|
||||
<div class="credentials-hint" v-if="selectedProviderType?.docs_url">
|
||||
<a :href="selectedProviderType.docs_url" target="_blank" rel="noopener noreferrer">
|
||||
{{ t('webSearchSettings.viewDocs') }} ↗
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<t-form-item v-if="selectedProviderType?.requires_api_key" :label="t('webSearchSettings.apiKeyLabel')" name="parameters.api_key">
|
||||
<t-input
|
||||
v-model="providerForm.parameters.api_key"
|
||||
type="password"
|
||||
:placeholder="editingProvider ? t('webSearchSettings.apiKeyUnchanged') : t('webSearchSettings.apiKeyPlaceholder')"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="selectedProviderType?.requires_engine_id" :label="t('webSearchSettings.engineIdLabel')" name="parameters.engine_id">
|
||||
<t-input v-model="providerForm.parameters.engine_id" :placeholder="t('webSearchSettings.engineIdLabel')" />
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<div class="form-divider"></div>
|
||||
|
||||
<t-form-item :label="t('webSearchSettings.setAsDefault')" name="is_default">
|
||||
<template #help>
|
||||
<div class="switch-help">
|
||||
{{ t('webSearchSettings.setAsDefaultDesc') }}
|
||||
</div>
|
||||
</template>
|
||||
<t-switch v-model="providerForm.is_default" />
|
||||
</t-form-item>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="footer-left">
|
||||
<t-button
|
||||
v-if="selectedProviderType && !selectedProviderType.free"
|
||||
theme="default"
|
||||
variant="outline"
|
||||
:loading="testing"
|
||||
@click="testConnection"
|
||||
>
|
||||
{{ testing ? t('webSearchSettings.testing') : t('webSearchSettings.testConnection') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="footer-right">
|
||||
<t-button theme="default" variant="base" @click="showAddProviderDialog = false">{{ t('common.cancel') }}</t-button>
|
||||
<t-button theme="primary" type="submit" :loading="saving">{{ t('common.save') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</t-form>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getWebSearchProviders, getTenantWebSearchConfig, updateTenantWebSearchConfig, type WebSearchProviderConfig, type WebSearchConfig } from '@/api/web-search'
|
||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||
import {
|
||||
listWebSearchProviders,
|
||||
listWebSearchProviderTypes,
|
||||
createWebSearchProvider,
|
||||
updateWebSearchProvider,
|
||||
deleteWebSearchProvider as deleteWebSearchProviderAPI,
|
||||
testWebSearchProvider,
|
||||
type WebSearchProviderEntity,
|
||||
type WebSearchProviderTypeInfo,
|
||||
} from '@/api/web-search-provider'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// 本地状态
|
||||
const loadingProviders = ref(false)
|
||||
const providers = ref<WebSearchProviderConfig[]>([])
|
||||
const localProvider = ref<string>('')
|
||||
const localAPIKey = ref<string>('')
|
||||
const localMaxResults = ref<number>(5)
|
||||
const localIncludeDate = ref<boolean>(true)
|
||||
const localCompressionMethod = ref<string>('none')
|
||||
const localBlacklistText = ref<string>('')
|
||||
const isInitializing = ref(true) // 标记是否正在初始化,初始化期间不触发自动保存
|
||||
const initialConfig = ref<WebSearchConfig | null>(null) // 保存初始配置,用于比较是否有变化
|
||||
// ===== State =====
|
||||
const providerEntities = ref<WebSearchProviderEntity[]>([])
|
||||
const providerTypes = ref<WebSearchProviderTypeInfo[]>([])
|
||||
const showAddProviderDialog = ref(false)
|
||||
const editingProvider = ref<WebSearchProviderEntity | null>(null)
|
||||
const testing = ref(false)
|
||||
const testingId = ref<string | null>(null)
|
||||
const saving = ref(false)
|
||||
|
||||
// 计算属性:当前选中的提供商
|
||||
const selectedProvider = computed(() => {
|
||||
return providers.value.find(p => p.id === localProvider.value)
|
||||
const providerForm = ref<{
|
||||
name: string
|
||||
provider: string
|
||||
description: string
|
||||
parameters: { api_key?: string; engine_id?: string }
|
||||
is_default: boolean
|
||||
}>({
|
||||
name: '',
|
||||
provider: 'duckduckgo',
|
||||
description: '',
|
||||
parameters: {},
|
||||
is_default: false,
|
||||
})
|
||||
|
||||
// 加载提供商列表
|
||||
const loadProviders = async () => {
|
||||
if (providers.value.length > 0) {
|
||||
return // 已加载过
|
||||
}
|
||||
|
||||
loadingProviders.value = true
|
||||
// ===== Computed =====
|
||||
const selectedProviderType = computed(() => {
|
||||
return providerTypes.value.find(pt => pt.id === providerForm.value.provider)
|
||||
})
|
||||
|
||||
// ===== Methods =====
|
||||
const onProviderTypeChange = () => {
|
||||
providerForm.value.parameters = {}
|
||||
}
|
||||
|
||||
const loadProviderEntities = async () => {
|
||||
try {
|
||||
const response = await getWebSearchProviders()
|
||||
// request拦截器已经处理了响应,直接使用data字段
|
||||
const response = await listWebSearchProviders()
|
||||
if (response.data && Array.isArray(response.data)) {
|
||||
providers.value = response.data
|
||||
providerEntities.value = response.data
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Failed to load web search providers:', error)
|
||||
const errorMessage = error?.message || t('webSearchSettings.errors.unknown')
|
||||
MessagePlugin.error(t('webSearchSettings.toasts.loadProvidersFailed', { message: errorMessage }))
|
||||
} finally {
|
||||
loadingProviders.value = false
|
||||
} catch (error) {
|
||||
console.error('Failed to load provider entities:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载租户配置
|
||||
const loadTenantConfig = async () => {
|
||||
const loadProviderTypes = async () => {
|
||||
try {
|
||||
const response = await getTenantWebSearchConfig()
|
||||
// request拦截器已经处理了响应,直接使用data字段
|
||||
if (response.data) {
|
||||
const config = response.data
|
||||
// 在设置初始值时,禁用自动保存
|
||||
isInitializing.value = true
|
||||
|
||||
// 保存初始配置的副本(用于后续比较)
|
||||
const blacklist = (config.blacklist || []).join('\n')
|
||||
initialConfig.value = {
|
||||
provider: config.provider || '',
|
||||
api_key: config.api_key === '***' ? '***' : config.api_key || '',
|
||||
max_results: config.max_results || 5,
|
||||
include_date: config.include_date !== undefined ? config.include_date : true,
|
||||
compression_method: config.compression_method || 'none',
|
||||
blacklist: config.blacklist || []
|
||||
}
|
||||
|
||||
// 设置本地状态值
|
||||
localProvider.value = config.provider || ''
|
||||
// API key 在响应中被隐藏,如果是 "***",说明已配置但未返回实际值
|
||||
localAPIKey.value = config.api_key === '***' ? '***' : config.api_key || ''
|
||||
localMaxResults.value = config.max_results || 5
|
||||
localIncludeDate.value = config.include_date !== undefined ? config.include_date : true
|
||||
localCompressionMethod.value = config.compression_method || 'none'
|
||||
localBlacklistText.value = blacklist
|
||||
|
||||
// 等待所有响应式更新完成后再启用自动保存
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
// 使用 setTimeout 确保所有事件都已处理完毕
|
||||
setTimeout(() => {
|
||||
isInitializing.value = false
|
||||
}, 100)
|
||||
} else {
|
||||
// 如果没有配置数据,保存默认配置
|
||||
initialConfig.value = {
|
||||
provider: '',
|
||||
api_key: '',
|
||||
max_results: 5,
|
||||
include_date: true,
|
||||
compression_method: 'none',
|
||||
blacklist: []
|
||||
}
|
||||
await nextTick()
|
||||
setTimeout(() => {
|
||||
isInitializing.value = false
|
||||
}, 100)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Failed to load tenant web search config:', error)
|
||||
// 如果配置不存在,使用默认值(不显示错误)
|
||||
initialConfig.value = {
|
||||
provider: '',
|
||||
providerTypes.value = await listWebSearchProviderTypes()
|
||||
} catch (error) {
|
||||
console.error('Failed to load provider types:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const openAddDialog = () => {
|
||||
editingProvider.value = null
|
||||
providerForm.value = {
|
||||
name: '',
|
||||
provider: providerTypes.value[0]?.id || 'duckduckgo',
|
||||
description: '',
|
||||
parameters: {},
|
||||
is_default: providerEntities.value.length === 0
|
||||
}
|
||||
showAddProviderDialog.value = true
|
||||
}
|
||||
|
||||
const editProvider = (entity: WebSearchProviderEntity) => {
|
||||
editingProvider.value = entity
|
||||
providerForm.value = {
|
||||
name: entity.name,
|
||||
provider: entity.provider,
|
||||
description: entity.description || '',
|
||||
parameters: {
|
||||
api_key: '',
|
||||
max_results: 5,
|
||||
include_date: true,
|
||||
compression_method: 'none',
|
||||
blacklist: []
|
||||
}
|
||||
await nextTick()
|
||||
setTimeout(() => {
|
||||
isInitializing.value = false
|
||||
}, 100)
|
||||
engine_id: entity.parameters?.engine_id || '',
|
||||
},
|
||||
is_default: entity.is_default || false,
|
||||
}
|
||||
showAddProviderDialog.value = true
|
||||
}
|
||||
|
||||
// 检查配置是否有变化
|
||||
const hasConfigChanged = (): boolean => {
|
||||
if (!initialConfig.value) {
|
||||
return true // 如果没有初始配置,认为有变化
|
||||
}
|
||||
|
||||
const blacklist = localBlacklistText.value
|
||||
.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line.length > 0)
|
||||
|
||||
const currentConfig: WebSearchConfig = {
|
||||
provider: localProvider.value,
|
||||
api_key: localAPIKey.value,
|
||||
max_results: localMaxResults.value,
|
||||
include_date: localIncludeDate.value,
|
||||
compression_method: localCompressionMethod.value,
|
||||
blacklist: blacklist
|
||||
}
|
||||
|
||||
// 比较配置是否有变化(忽略 API key 的 '***' 占位符)
|
||||
const initial = initialConfig.value
|
||||
if (currentConfig.provider !== initial.provider) return true
|
||||
if (currentConfig.api_key !== initial.api_key &&
|
||||
!(currentConfig.api_key === '***' && initial.api_key === '***')) return true
|
||||
if (currentConfig.max_results !== initial.max_results) return true
|
||||
if (currentConfig.include_date !== initial.include_date) return true
|
||||
if (currentConfig.compression_method !== initial.compression_method) return true
|
||||
|
||||
// 比较黑名单数组
|
||||
const currentBlacklist = blacklist.sort().join(',')
|
||||
const initialBlacklist = (initial.blacklist || []).sort().join(',')
|
||||
if (currentBlacklist !== initialBlacklist) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
const saveConfig = async () => {
|
||||
// 如果配置没有变化,不保存
|
||||
if (!hasConfigChanged()) {
|
||||
const saveProvider = async ({ validateResult, firstError }: any) => {
|
||||
if (validateResult !== true && validateResult !== undefined) {
|
||||
MessagePlugin.warning(firstError || 'Please check the form fields')
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const blacklist = localBlacklistText.value
|
||||
.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line.length > 0)
|
||||
|
||||
const config: WebSearchConfig = {
|
||||
provider: localProvider.value,
|
||||
api_key: localAPIKey.value,
|
||||
max_results: localMaxResults.value,
|
||||
include_date: localIncludeDate.value,
|
||||
compression_method: localCompressionMethod.value,
|
||||
blacklist: blacklist
|
||||
const data: Partial<WebSearchProviderEntity> = {
|
||||
name: providerForm.value.name.trim() || selectedProviderType.value?.name || providerForm.value.provider,
|
||||
provider: providerForm.value.provider as any,
|
||||
description: providerForm.value.description,
|
||||
parameters: { ...providerForm.value.parameters },
|
||||
is_default: providerForm.value.is_default,
|
||||
}
|
||||
|
||||
await updateTenantWebSearchConfig(config)
|
||||
|
||||
// 更新初始配置,避免重复保存
|
||||
initialConfig.value = {
|
||||
provider: config.provider,
|
||||
api_key: config.api_key,
|
||||
max_results: config.max_results,
|
||||
include_date: config.include_date,
|
||||
compression_method: config.compression_method,
|
||||
blacklist: [...config.blacklist]
|
||||
if (editingProvider.value && !data.parameters!.api_key) {
|
||||
delete data.parameters!.api_key
|
||||
}
|
||||
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.saveSuccess'))
|
||||
|
||||
if (editingProvider.value) {
|
||||
await updateWebSearchProvider(editingProvider.value.id!, data)
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.providerUpdated'))
|
||||
} else {
|
||||
await createWebSearchProvider(data)
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.providerCreated'))
|
||||
}
|
||||
showAddProviderDialog.value = false
|
||||
await loadProviderEntities()
|
||||
} catch (error: any) {
|
||||
console.error('Failed to save web search config:', error)
|
||||
const errorMessage = error?.message || t('webSearchSettings.errors.unknown')
|
||||
MessagePlugin.error(t('webSearchSettings.toasts.saveFailed', { message: errorMessage }))
|
||||
throw error
|
||||
MessagePlugin.error(error?.message || 'Failed to save provider')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 防抖保存
|
||||
let saveTimer: number | null = null
|
||||
const debouncedSave = () => {
|
||||
// 初始化期间不触发自动保存
|
||||
if (isInitializing.value) {
|
||||
return
|
||||
const deleteProvider = async (id: string) => {
|
||||
try {
|
||||
await deleteWebSearchProviderAPI(id)
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.providerDeleted'))
|
||||
await loadProviderEntities()
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || 'Failed to delete provider')
|
||||
}
|
||||
if (saveTimer) {
|
||||
clearTimeout(saveTimer)
|
||||
}
|
||||
|
||||
const testConnection = async () => {
|
||||
testing.value = true
|
||||
try {
|
||||
const data = {
|
||||
provider: providerForm.value.provider,
|
||||
parameters: { ...providerForm.value.parameters },
|
||||
}
|
||||
|
||||
if (editingProvider.value && !data.parameters.api_key) {
|
||||
const res = await testWebSearchProvider(editingProvider.value.id!)
|
||||
if (res.success) {
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.testSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(res.error || t('webSearchSettings.toasts.testFailed'))
|
||||
}
|
||||
} else {
|
||||
const res = await testWebSearchProvider(undefined, data)
|
||||
if (res.success) {
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.testSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(res.error || t('webSearchSettings.toasts.testFailed'))
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('webSearchSettings.toasts.testFailed'))
|
||||
} finally {
|
||||
testing.value = false
|
||||
}
|
||||
saveTimer = window.setTimeout(() => {
|
||||
saveConfig().catch(() => {
|
||||
// 错误已在 saveConfig 中处理
|
||||
})
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 处理变化
|
||||
const handleProviderChange = () => {
|
||||
debouncedSave()
|
||||
const testExistingConnection = async (entity: WebSearchProviderEntity) => {
|
||||
testingId.value = entity.id!
|
||||
try {
|
||||
const res = await testWebSearchProvider(entity.id!)
|
||||
if (res.success) {
|
||||
MessagePlugin.success(t('webSearchSettings.toasts.testSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(res.error || t('webSearchSettings.toasts.testFailed'))
|
||||
}
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('webSearchSettings.toasts.testFailed'))
|
||||
} finally {
|
||||
testingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const handleAPIKeyChange = () => {
|
||||
debouncedSave()
|
||||
}
|
||||
|
||||
const handleMaxResultsChange = () => {
|
||||
debouncedSave()
|
||||
}
|
||||
|
||||
const handleIncludeDateChange = () => {
|
||||
debouncedSave()
|
||||
}
|
||||
|
||||
const handleCompressionMethodChange = () => {
|
||||
debouncedSave()
|
||||
}
|
||||
|
||||
const handleBlacklistChange = () => {
|
||||
debouncedSave()
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// ===== Init =====
|
||||
onMounted(async () => {
|
||||
isInitializing.value = true
|
||||
await loadProviders()
|
||||
await loadTenantConfig()
|
||||
// loadTenantConfig 内部已经处理了 isInitializing,这里不需要再设置
|
||||
await Promise.all([loadProviderTypes(), loadProviderEntities()])
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -409,139 +354,130 @@ onMounted(async () => {
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
.section-subheader {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
margin-bottom: 16px;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&.vertical {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
|
||||
.setting-control {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
.provider-list {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.slider-with-value {
|
||||
.provider-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
justify-content: space-between;
|
||||
padding: 14px 16px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
.value-display {
|
||||
min-width: 40px;
|
||||
text-align: right;
|
||||
.item-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.provider-option-wrapper {
|
||||
.item-desc {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 2px 0;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-providers {
|
||||
padding: 32px;
|
||||
text-align: center;
|
||||
color: var(--td-text-color-placeholder);
|
||||
border: 1px dashed var(--td-component-stroke);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.dialog-form-container {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.provider-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.provider-name {
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.provider-tags {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
flex-shrink: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.provider-desc {
|
||||
.form-divider {
|
||||
height: 1px;
|
||||
background: var(--td-component-border);
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.credentials-hint {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
|
||||
a {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.switch-help {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-top: 4px;
|
||||
line-height: 1.4;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* 修复下拉项描述与条目重叠:让选项支持多行自适应高度 */
|
||||
:deep(.t-select-option) {
|
||||
height: auto;
|
||||
align-items: flex-start;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
:deep(.t-select-option__content) {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
</style>
|
||||
<style lang="less">
|
||||
.t-select__dropdown .t-select-option {
|
||||
height: auto;
|
||||
align-items: flex-start;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
.t-select__dropdown .t-select-option__content {
|
||||
white-space: normal;
|
||||
}
|
||||
.t-select__dropdown .provider-option-wrapper {
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 2px 0;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 32px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--td-component-border);
|
||||
|
||||
.footer-right {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user