From 4191d878f294463e597de2b7dbbd095d3b01e8f7 Mon Sep 17 00:00:00 2001 From: one Date: Thu, 21 Aug 2025 16:59:04 +0800 Subject: [PATCH] fix: do not reset citation block (#9383) * fix: do not reset citation block id * refactor: disable external websearch for mandatory websearch models * refactor: predicate * refactor: include openrouter perplexity --- src/renderer/src/config/models.ts | 15 +++++++++++++++ src/renderer/src/pages/home/Inputbar/Inputbar.tsx | 6 +++++- .../src/pages/home/Inputbar/InputbarTools.tsx | 5 +++-- .../callbacks/citationCallbacks.ts | 5 +---- .../services/messageStreaming/callbacks/index.ts | 3 +-- .../messageStreaming/callbacks/textCallbacks.ts | 4 +--- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/config/models.ts b/src/renderer/src/config/models.ts index a4fdcf0fb9..ac2a527a9c 100644 --- a/src/renderer/src/config/models.ts +++ b/src/renderer/src/config/models.ts @@ -3004,6 +3004,21 @@ export function isWebSearchModel(model: Model): boolean { return false } +export function isMandatoryWebSearchModel(model: Model): boolean { + if (!model) { + return false + } + + const provider = getProviderByModel(model) + const modelId = getLowerBaseModelName(model.id) + + if (provider.id === 'perplexity' || provider.id === 'openrouter') { + return PERPLEXITY_SEARCH_MODELS.includes(modelId) + } + + return false +} + export function isOpenRouterBuiltInWebSearchModel(model: Model): boolean { if (!model) { return false diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index f36af1635e..e2de99df8c 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -5,6 +5,7 @@ import TranslateButton from '@renderer/components/TranslateButton' import { isGenerateImageModel, isGenerateImageModels, + isMandatoryWebSearchModel, isSupportedDisableGenerationModel, isSupportedReasoningEffortModel, isSupportedThinkingTokenModel, @@ -767,7 +768,10 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = if (!isWebSearchModel(model) && assistant.enableWebSearch) { updateAssistant({ ...assistant, enableWebSearch: false }) } - if (assistant.webSearchProviderId && !WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId)) { + if ( + assistant.webSearchProviderId && + (!WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId) || isMandatoryWebSearchModel(model)) + ) { updateAssistant({ ...assistant, webSearchProviderId: undefined }) } if (!isGenerateImageModel(model) && assistant.enableGenerateImage) { diff --git a/src/renderer/src/pages/home/Inputbar/InputbarTools.tsx b/src/renderer/src/pages/home/Inputbar/InputbarTools.tsx index 426bd8957c..0f60ef9e7f 100644 --- a/src/renderer/src/pages/home/Inputbar/InputbarTools.tsx +++ b/src/renderer/src/pages/home/Inputbar/InputbarTools.tsx @@ -1,6 +1,6 @@ import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd' import { QuickPanelListItem } from '@renderer/components/QuickPanel' -import { isGenerateImageModel } from '@renderer/config/models' +import { isGenerateImageModel, isMandatoryWebSearchModel } from '@renderer/config/models' import { useAppDispatch, useAppSelector } from '@renderer/store' import { setIsCollapsed, setToolOrder } from '@renderer/store/inputTools' import { Assistant, FileType, KnowledgeBase, Model } from '@renderer/types' @@ -340,7 +340,8 @@ const InputbarTools = ({ { key: 'web_search', label: t('chat.input.web_search.label'), - component: + component: , + condition: !isMandatoryWebSearchModel(model) }, { key: 'url_context', diff --git a/src/renderer/src/services/messageStreaming/callbacks/citationCallbacks.ts b/src/renderer/src/services/messageStreaming/callbacks/citationCallbacks.ts index 03d0f23d48..56d0680839 100644 --- a/src/renderer/src/services/messageStreaming/callbacks/citationCallbacks.ts +++ b/src/renderer/src/services/messageStreaming/callbacks/citationCallbacks.ts @@ -120,9 +120,6 @@ export const createCitationCallbacks = (deps: CitationCallbacksDependencies) => }, // 暴露给外部的方法,用于textCallbacks中获取citationBlockId - getCitationBlockId: () => citationBlockId, - setCitationBlockId: (id: string | null) => { - citationBlockId = id - } + getCitationBlockId: () => citationBlockId } } diff --git a/src/renderer/src/services/messageStreaming/callbacks/index.ts b/src/renderer/src/services/messageStreaming/callbacks/index.ts index ada8ed7b67..2b6fc5968a 100644 --- a/src/renderer/src/services/messageStreaming/callbacks/index.ts +++ b/src/renderer/src/services/messageStreaming/callbacks/index.ts @@ -59,8 +59,7 @@ export const createCallbacks = (deps: CallbacksDependencies) => { blockManager, getState, assistantMsgId, - getCitationBlockId: citationCallbacks.getCitationBlockId, - setCitationBlockId: citationCallbacks.setCitationBlockId + getCitationBlockId: citationCallbacks.getCitationBlockId }) // 组合所有回调 diff --git a/src/renderer/src/services/messageStreaming/callbacks/textCallbacks.ts b/src/renderer/src/services/messageStreaming/callbacks/textCallbacks.ts index 53621b625f..657cf6f0f3 100644 --- a/src/renderer/src/services/messageStreaming/callbacks/textCallbacks.ts +++ b/src/renderer/src/services/messageStreaming/callbacks/textCallbacks.ts @@ -12,11 +12,10 @@ interface TextCallbacksDependencies { getState: any assistantMsgId: string getCitationBlockId: () => string | null - setCitationBlockId: (id: string | null) => void } export const createTextCallbacks = (deps: TextCallbacksDependencies) => { - const { blockManager, getState, assistantMsgId, getCitationBlockId, setCitationBlockId } = deps + const { blockManager, getState, assistantMsgId, getCitationBlockId } = deps // 内部维护的状态 let mainTextBlockId: string | null = null @@ -63,7 +62,6 @@ export const createTextCallbacks = (deps: TextCallbacksDependencies) => { } blockManager.smartBlockUpdate(mainTextBlockId, changes, MessageBlockType.MAIN_TEXT, true) mainTextBlockId = null - setCitationBlockId(null) } else { logger.warn( `[onTextComplete] Received text.complete but last block was not MAIN_TEXT (was ${blockManager.lastBlockType}) or lastBlockId is null.`