feature: Hide disabled options for web search (#5943)

* refactor(WebSearchButton): streamline provider item creation and filter disabled items

* refactor(WebSearchButton): optimize provider items mapping and add pageSize to quick panel

* refactor(WebSearchButton): filter out disabled providers in items mapping
This commit is contained in:
Teo 2025-05-13 12:07:08 +08:00 committed by GitHub
parent e4d1dd0c87
commit dac200f330
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,29 +50,34 @@ const WebSearchButton: FC<Props> = ({ ref, assistant, ToolbarButton }) => {
const providerItems = useMemo<QuickPanelListItem[]>(() => {
const isWebSearchModelEnabled = assistant.model && isWebSearchModel(assistant.model)
const items: QuickPanelListItem[] = providers.map((p) => ({
label: p.name,
description: WebSearchService.isWebSearchEnabled(p.id)
? hasObjectKey(p, 'apiKey')
? t('settings.websearch.apikey')
: t('settings.websearch.free')
: t('chat.input.web_search.enable_content'),
icon: <Globe />,
isSelected: p.id === assistant?.webSearchProviderId,
disabled: !WebSearchService.isWebSearchEnabled(p.id),
action: () => updateSelectedWebSearchProvider(p.id)
}))
const items: QuickPanelListItem[] = providers
.map((p) => ({
label: p.name,
description: WebSearchService.isWebSearchEnabled(p.id)
? hasObjectKey(p, 'apiKey')
? t('settings.websearch.apikey')
: t('settings.websearch.free')
: t('chat.input.web_search.enable_content'),
icon: <Globe />,
isSelected: p.id === assistant?.webSearchProviderId,
disabled: !WebSearchService.isWebSearchEnabled(p.id),
action: () => updateSelectedWebSearchProvider(p.id)
}))
.filter((o) => !o.disabled)
if (isWebSearchModelEnabled) {
items.unshift({
label: t('chat.input.web_search.builtin'),
description: isWebSearchModelEnabled
? t('chat.input.web_search.builtin.enabled_content')
: t('chat.input.web_search.builtin.disabled_content'),
icon: <Globe />,
isSelected: assistant.enableWebSearch,
disabled: !isWebSearchModelEnabled,
action: () => updateSelectedWebSearchBuiltin()
})
}
items.unshift({
label: t('chat.input.web_search.builtin'),
description: isWebSearchModelEnabled
? t('chat.input.web_search.builtin.enabled_content')
: t('chat.input.web_search.builtin.disabled_content'),
icon: <Globe />,
isSelected: assistant.enableWebSearch,
disabled: !isWebSearchModelEnabled,
action: () => updateSelectedWebSearchBuiltin()
})
items.push({
label: '前往设置' + '...',
icon: <Settings />,
@ -105,7 +110,8 @@ const WebSearchButton: FC<Props> = ({ ref, assistant, ToolbarButton }) => {
quickPanel.open({
title: t('chat.input.web_search'),
list: providerItems,
symbol: '?'
symbol: '?',
pageSize: 9
})
}, [quickPanel, providerItems, t])