fix(selection): fix missing settings (#9454)

* fix(selection): 修复流式输出设置合并问题并添加调试日志

确保assistant的settings在设置streamOutput时保留原有属性
在ActionGeneral组件中添加处理消息前的调试日志

* style: 移除 TabContainer 组件中的多余空行

* fix(HomeWindow): 修复助手设置被覆盖的问题

* refactor(assistant): 优化助手设置处理逻辑,避免重复创建对象

统一处理助手设置逻辑,确保streamOutput属性存在
在多个地方避免直接修改currentAssistant,改为创建新对象

* fix: 使用cloneDeep替代对象展开并显式关闭功能

修复对象浅拷贝可能导致的问题,使用lodash的cloneDeep进行深拷贝
显式关闭web搜索、mcp服务和知识库功能以确保一致性

* refactor: 注释掉未使用的功能配置以提升代码可读性
This commit is contained in:
Phantom 2025-08-24 17:00:49 +08:00 committed by GitHub
parent 17cee98617
commit fba358c0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 3 deletions

View File

@ -21,7 +21,7 @@ import { getMainTextContent } from '@renderer/utils/messageUtils/find'
import { defaultLanguage } from '@shared/config/constant'
import { IpcChannel } from '@shared/IpcChannel'
import { Divider } from 'antd'
import { isEmpty } from 'lodash'
import { cloneDeep, isEmpty } from 'lodash'
import { last } from 'lodash'
import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
@ -256,9 +256,19 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
setIsFirstMessage(false)
setUserInputText('')
const newAssistant = cloneDeep(currentAssistant)
if (!newAssistant.settings) {
newAssistant.settings = {}
}
newAssistant.settings.streamOutput = true
// 显式关闭这些功能
// newAssistant.webSearchProviderId = undefined
newAssistant.mcpServers = undefined
// newAssistant.knowledge_bases = undefined
await fetchChatCompletion({
messages: messagesForContext,
assistant: { ...currentAssistant, settings: { streamOutput: true } },
assistant: newAssistant,
onChunkReceived: (chunk: Chunk) => {
switch (chunk.type) {
case ChunkType.THINKING_START:

View File

@ -1,4 +1,5 @@
import { LoadingOutlined } from '@ant-design/icons'
import { loggerService } from '@logger'
import CopyButton from '@renderer/components/CopyButton'
import { useTopicMessages } from '@renderer/hooks/useMessageOperations'
import { useSettings } from '@renderer/hooks/useSettings'
@ -21,6 +22,7 @@ import styled from 'styled-components'
import { processMessages } from './ActionUtils'
import WindowFooter from './WindowFooter'
const logger = loggerService.withContext('ActionGeneral')
interface Props {
action: ActionItem
scrollToBottom?: () => void
@ -112,6 +114,7 @@ const ActionGeneral: FC<Props> = React.memo(({ action, scrollToBottom }) => {
}
if (!assistantRef.current || !topicRef.current) return
logger.debug('Before peocess message', { assistant: assistantRef.current })
processMessages(
assistantRef.current,
topicRef.current,

View File

@ -10,6 +10,7 @@ import { Chunk, ChunkType } from '@renderer/types/chunk'
import { AssistantMessageStatus, MessageBlockStatus } from '@renderer/types/newMessage'
import { formatErrorMessage, isAbortError } from '@renderer/utils/error'
import { createErrorBlock, createMainTextBlock, createThinkingBlock } from '@renderer/utils/messageUtils/create'
import { cloneDeep } from 'lodash'
const logger = loggerService.withContext('ActionUtils')
@ -53,9 +54,19 @@ export const processMessages = async (
let finished = false
const newAssistant = cloneDeep(assistant)
if (!newAssistant.settings) {
newAssistant.settings = {}
}
newAssistant.settings.streamOutput = true
// 显式关闭这些功能
newAssistant.webSearchProviderId = undefined
newAssistant.mcpServers = undefined
// newAssistant.knowledge_bases = undefined
await fetchChatCompletion({
messages: [userMessage],
assistant: { ...assistant, settings: { streamOutput: true } },
assistant: newAssistant,
onChunkReceived: (chunk: Chunk) => {
if (finished) {
return