feat(web-search): add Zhipu AI web search provider support
Integrate Zhipu's standalone Web Search API with configurable search engine and content size options, plus settings UI, docs, and tests.
This commit is contained in:
@@ -5,7 +5,7 @@ export interface WebSearchProviderEntity {
|
||||
id?: string
|
||||
tenant_id?: number
|
||||
name: string
|
||||
provider: 'bing' | 'google' | 'duckduckgo' | 'tavily' | 'ollama' | 'baidu' | 'searxng' | 'keenable'
|
||||
provider: 'bing' | 'google' | 'duckduckgo' | 'tavily' | 'ollama' | 'baidu' | 'searxng' | 'keenable' | 'zhipu'
|
||||
description?: string
|
||||
parameters: {
|
||||
// api_key is never returned by the server in this shape; it lives behind
|
||||
@@ -36,6 +36,19 @@ export interface WebSearchProviderTypeInfo {
|
||||
supports_proxy?: boolean
|
||||
description?: string
|
||||
docs_url?: string
|
||||
config_fields?: WebSearchProviderConfigField[]
|
||||
}
|
||||
|
||||
export interface WebSearchProviderConfigField {
|
||||
key: string
|
||||
label: string
|
||||
label_key?: string
|
||||
type: 'select'
|
||||
required?: boolean
|
||||
default?: string
|
||||
description?: string
|
||||
description_key?: string
|
||||
options?: Array<{ label: string; label_key?: string; value: string }>
|
||||
}
|
||||
|
||||
// Create a new web search provider
|
||||
|
||||
@@ -1558,6 +1558,18 @@ export default {
|
||||
basicInfo: "Basic Information",
|
||||
credentials: "Credentials",
|
||||
setAsDefaultDesc: "This provider will be used by default when an agent doesn't specify one",
|
||||
configFields: {
|
||||
searchEngine: 'Search engine',
|
||||
searchEngineDesc: 'Select the Zhipu search engine and per-request price tier.',
|
||||
searchStd: 'Standard · ¥0.01/request',
|
||||
searchPro: 'Pro · ¥0.03/request',
|
||||
searchSogou: 'Sogou · ¥0.05/request',
|
||||
searchQuark: 'Quark · ¥0.05/request',
|
||||
contentSize: 'Content size',
|
||||
contentSizeDesc: 'Medium returns concise summaries; high returns more context.',
|
||||
contentMedium: 'Medium',
|
||||
contentHigh: 'High',
|
||||
},
|
||||
// Search behavior
|
||||
searchBehaviorTitle: 'Search Behavior',
|
||||
defaultProviderLabel: 'Default Provider',
|
||||
|
||||
@@ -1422,6 +1422,18 @@ export default {
|
||||
basicInfo: "기본 정보",
|
||||
credentials: "자격 증명",
|
||||
setAsDefaultDesc: "에이전트가 검색 엔진을 지정하지 않은 경우 이 프로바이더가 기본적으로 사용됩니다",
|
||||
configFields: {
|
||||
searchEngine: "검색 엔진",
|
||||
searchEngineDesc: "Zhipu 검색 엔진과 요청당 요금제를 선택합니다.",
|
||||
searchStd: "Standard · ¥0.01/요청",
|
||||
searchPro: "Pro · ¥0.03/요청",
|
||||
searchSogou: "Sogou · ¥0.05/요청",
|
||||
searchQuark: "Quark · ¥0.05/요청",
|
||||
contentSize: "콘텐츠 길이",
|
||||
contentSizeDesc: "Medium은 간결한 요약을, High는 더 많은 컨텍스트를 반환합니다.",
|
||||
contentMedium: "Medium",
|
||||
contentHigh: "High",
|
||||
},
|
||||
searchBehaviorTitle: "검색 동작 설정",
|
||||
defaultProviderLabel: "기본 프로바이더",
|
||||
defaultProviderDescription: "자체 프로바이더를 지정하지 않은 에이전트의 기본 검색 프로바이더를 선택합니다",
|
||||
|
||||
@@ -1466,6 +1466,18 @@ export default {
|
||||
basicInfo: "Основная информация",
|
||||
credentials: "Учетные данные",
|
||||
setAsDefaultDesc: "Этот провайдер будет использоваться по умолчанию, если агент не укажет свой",
|
||||
configFields: {
|
||||
searchEngine: 'Поисковый движок',
|
||||
searchEngineDesc: 'Выберите поисковый движок Zhipu и соответствующий тариф за запрос.',
|
||||
searchStd: 'Standard · ¥0.01/запрос',
|
||||
searchPro: 'Pro · ¥0.03/запрос',
|
||||
searchSogou: 'Sogou · ¥0.05/запрос',
|
||||
searchQuark: 'Quark · ¥0.05/запрос',
|
||||
contentSize: 'Размер содержимого',
|
||||
contentSizeDesc: 'Medium возвращает краткие сводки, High — больше контекста.',
|
||||
contentMedium: 'Medium',
|
||||
contentHigh: 'High',
|
||||
},
|
||||
searchBehaviorTitle: 'Поведение поиска',
|
||||
defaultProviderLabel: 'Провайдер по умолчанию',
|
||||
defaultProviderDescription: 'Выберите провайдер поиска по умолчанию для агентов, не указавших собственный.',
|
||||
|
||||
@@ -1431,6 +1431,18 @@ export default {
|
||||
basicInfo: "基础信息",
|
||||
credentials: "凭证信息",
|
||||
setAsDefaultDesc: "当智能体没有指定特定的搜索引擎时,将默认使用此配置",
|
||||
configFields: {
|
||||
searchEngine: "搜索引擎",
|
||||
searchEngineDesc: "选择智谱搜索引擎及对应的单次调用价格档位。",
|
||||
searchStd: "基础版 · ¥0.01/次",
|
||||
searchPro: "高级版 · ¥0.03/次",
|
||||
searchSogou: "搜狗 · ¥0.05/次",
|
||||
searchQuark: "夸克 · ¥0.05/次",
|
||||
contentSize: "摘要长度",
|
||||
contentSizeDesc: "中等返回精简摘要;详细返回更多上下文。",
|
||||
contentMedium: "中等",
|
||||
contentHigh: "详细",
|
||||
},
|
||||
// Search behavior
|
||||
searchBehaviorTitle: "搜索行为配置",
|
||||
defaultProviderLabel: "默认搜索引擎",
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
|
||||
<!-- Section 2 — 连接配置(base url / api key / engine id),仅当任意字段需要时渲染 -->
|
||||
<section
|
||||
v-if="selectedProviderType?.requires_api_key || selectedProviderType?.supports_optional_api_key || selectedProviderType?.requires_engine_id || selectedProviderType?.requires_base_url"
|
||||
v-if="selectedProviderType?.requires_api_key || selectedProviderType?.supports_optional_api_key || selectedProviderType?.requires_engine_id || selectedProviderType?.requires_base_url || selectedProviderType?.config_fields?.length"
|
||||
class="setting-drawer__section"
|
||||
>
|
||||
<h4 class="setting-drawer__section-title">{{ t('webSearchSettings.credentialsSection', '连接配置') }}</h4>
|
||||
@@ -253,6 +253,30 @@
|
||||
:placeholder="t('webSearchSettings.engineIdLabel')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="field in selectedProviderType?.config_fields || []"
|
||||
:key="field.key"
|
||||
class="form-item"
|
||||
>
|
||||
<label class="form-label" :class="{ required: field.required }">
|
||||
{{ configFieldText(field.label_key, field.label) }}
|
||||
</label>
|
||||
<t-select
|
||||
v-if="field.type === 'select'"
|
||||
v-model="providerForm.parameters.extra_config[field.key]"
|
||||
>
|
||||
<t-option
|
||||
v-for="option in field.options || []"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="configFieldText(option.label_key, option.label)"
|
||||
/>
|
||||
</t-select>
|
||||
<p v-if="field.description" class="form-desc">
|
||||
{{ configFieldText(field.description_key, field.description) }}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Section 3 — 选项(代理 / 默认) -->
|
||||
@@ -334,13 +358,19 @@ const providerForm = ref<{
|
||||
name: string
|
||||
provider: string
|
||||
description: string
|
||||
parameters: { api_key?: string; engine_id?: string; base_url?: string; proxy_url?: string }
|
||||
parameters: {
|
||||
api_key?: string
|
||||
engine_id?: string
|
||||
base_url?: string
|
||||
proxy_url?: string
|
||||
extra_config: Record<string, string>
|
||||
}
|
||||
is_default: boolean
|
||||
}>({
|
||||
name: '',
|
||||
provider: 'duckduckgo',
|
||||
description: '',
|
||||
parameters: {},
|
||||
parameters: { extra_config: {} },
|
||||
is_default: false,
|
||||
})
|
||||
|
||||
@@ -355,6 +385,7 @@ watch(
|
||||
providerForm.value.parameters?.api_key,
|
||||
providerForm.value.parameters?.engine_id,
|
||||
providerForm.value.parameters?.base_url,
|
||||
JSON.stringify(providerForm.value.parameters?.extra_config || {}),
|
||||
],
|
||||
() => { lastTestOk.value = null },
|
||||
)
|
||||
@@ -425,6 +456,7 @@ const canTestConnection = computed(() => {
|
||||
if (pt.requires_api_key && !providerForm.value.parameters.api_key) return false
|
||||
if (pt.requires_engine_id && !providerForm.value.parameters.engine_id) return false
|
||||
if (pt.requires_base_url && !providerForm.value.parameters.base_url) return false
|
||||
if (pt.config_fields?.some(field => field.required && !providerForm.value.parameters.extra_config?.[field.key])) return false
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -455,9 +487,24 @@ const providerTypeLabel = (providerId: string) => {
|
||||
return providerTypes.value.find(p => p.id === providerId)?.name || providerId
|
||||
}
|
||||
|
||||
const configFieldText = (key: string | undefined, fallback: string) => {
|
||||
return key ? t(key, fallback) : fallback
|
||||
}
|
||||
|
||||
const providerConfigDefaults = (providerId: string) => {
|
||||
const fields = providerTypes.value.find(p => p.id === providerId)?.config_fields || []
|
||||
return Object.fromEntries(
|
||||
fields
|
||||
.filter(field => field.default !== undefined)
|
||||
.map(field => [field.key, field.default as string]),
|
||||
)
|
||||
}
|
||||
|
||||
// ===== Methods =====
|
||||
const onProviderTypeChange = () => {
|
||||
providerForm.value.parameters = {}
|
||||
providerForm.value.parameters = {
|
||||
extra_config: providerConfigDefaults(providerForm.value.provider),
|
||||
}
|
||||
lastTestOk.value = null
|
||||
}
|
||||
|
||||
@@ -486,7 +533,9 @@ const openAddDialog = () => {
|
||||
name: '',
|
||||
provider: providerTypes.value[0]?.id || 'duckduckgo',
|
||||
description: '',
|
||||
parameters: {},
|
||||
parameters: {
|
||||
extra_config: providerConfigDefaults(providerTypes.value[0]?.id || 'duckduckgo'),
|
||||
},
|
||||
is_default: providerEntities.value.length === 0
|
||||
}
|
||||
lastTestOk.value = null
|
||||
@@ -506,6 +555,10 @@ const editProvider = (entity: WebSearchProviderEntity) => {
|
||||
engine_id: entity.parameters?.engine_id || '',
|
||||
base_url: entity.parameters?.base_url || '',
|
||||
proxy_url: entity.parameters?.proxy_url || '',
|
||||
extra_config: {
|
||||
...providerConfigDefaults(entity.provider),
|
||||
...(entity.parameters?.extra_config || {}),
|
||||
},
|
||||
},
|
||||
is_default: entity.is_default || false,
|
||||
}
|
||||
@@ -531,6 +584,13 @@ const saveProvider = async () => {
|
||||
base_url: providerForm.value.parameters.base_url,
|
||||
proxy_url: providerForm.value.parameters.proxy_url,
|
||||
}
|
||||
const extraConfig = Object.fromEntries(
|
||||
Object.entries(providerForm.value.parameters.extra_config || {})
|
||||
.filter(([, value]) => value !== ''),
|
||||
)
|
||||
if (Object.keys(extraConfig).length > 0) {
|
||||
paramsOut.extra_config = extraConfig
|
||||
}
|
||||
if (!editingProvider.value && providerForm.value.parameters.api_key) {
|
||||
paramsOut.api_key = providerForm.value.parameters.api_key
|
||||
}
|
||||
@@ -855,6 +915,10 @@ onMounted(async () => {
|
||||
background: rgba(20, 158, 130, 0.12);
|
||||
color: #149E82;
|
||||
}
|
||||
.provider-card--zhipu .provider-card__badge {
|
||||
background: rgba(37, 99, 235, 0.12);
|
||||
color: #2563EB;
|
||||
}
|
||||
|
||||
.provider-card__body {
|
||||
flex: 1;
|
||||
@@ -1133,4 +1197,8 @@ onMounted(async () => {
|
||||
background: rgba(20, 158, 130, 0.12);
|
||||
color: #149E82;
|
||||
}
|
||||
.websearch-drawer--zhipu .setting-drawer__header-icon {
|
||||
background: rgba(37, 99, 235, 0.12);
|
||||
color: #2563EB;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user