fix(MCPSettings, OpenAIProvider): Update settings and content handling
- Prevent modal from closing on mask click in MCPSettings - Ensure tool call response content is properly formatted as a string in OpenAIProvider
This commit is contained in:
parent
7122d44b13
commit
fb27be0f59
@ -712,7 +712,11 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
disabled={files.length > 0}
|
||||
/>
|
||||
)}
|
||||
<MCPToolsButton enabledMCPs={enabledMCPs} onEnableMCP={toggelEnableMCP} ToolbarButton={ToolbarButton} />
|
||||
<MCPToolsButton
|
||||
enabledMCPs={enabledMCPs}
|
||||
toggelEnableMCP={toggelEnableMCP}
|
||||
ToolbarButton={ToolbarButton}
|
||||
/>
|
||||
<AttachmentButton model={model} files={files} setFiles={setFiles} ToolbarButton={ToolbarButton} />
|
||||
<Tooltip placement="top" title={t('chat.input.clear', { Command: cleanTopicShortcut })} arrow>
|
||||
<Popconfirm
|
||||
|
||||
@ -2,20 +2,20 @@ import { CodeOutlined } from '@ant-design/icons'
|
||||
import { useMCPServers } from '@renderer/hooks/useMCPServers'
|
||||
import { MCPServer } from '@renderer/types'
|
||||
import { Dropdown, Switch, Tooltip } from 'antd'
|
||||
import { FC, useEffect, useRef, useState } from 'react'
|
||||
import { every } from 'lodash'
|
||||
import { FC, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
|
||||
interface Props {
|
||||
enabledMCPs: MCPServer[]
|
||||
onEnableMCP: (server: MCPServer) => void
|
||||
toggelEnableMCP: (server: MCPServer) => void
|
||||
ToolbarButton: any
|
||||
}
|
||||
|
||||
const MCPToolsButton: FC<Props> = ({ enabledMCPs, onEnableMCP, ToolbarButton }) => {
|
||||
const MCPToolsButton: FC<Props> = ({ enabledMCPs, toggelEnableMCP, ToolbarButton }) => {
|
||||
const { mcpServers } = useMCPServers()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [enableAll, setEnableAll] = useState(false)
|
||||
const dropdownRef = useRef<any>(null)
|
||||
const menuRef = useRef<HTMLDivElement>(null)
|
||||
const { t } = useTranslation()
|
||||
@ -28,19 +28,11 @@ const MCPToolsButton: FC<Props> = ({ enabledMCPs, onEnableMCP, ToolbarButton })
|
||||
// Check if all active servers are enabled
|
||||
const activeServers = mcpServers.filter((s) => s.isActive)
|
||||
|
||||
// This effect only runs when enableAll changes, not on every render
|
||||
useEffect(() => {
|
||||
if (activeServers.length > 0) {
|
||||
activeServers.forEach((server) => {
|
||||
const isServerEnabled = enabledMCPs.includes(server)
|
||||
if (enableAll && !isServerEnabled) {
|
||||
onEnableMCP(server) // Enable server if enableAll is true and server is disabled
|
||||
} else if (!enableAll && isServerEnabled) {
|
||||
onEnableMCP(server) // Disable server if enableAll is false and server is enabled
|
||||
}
|
||||
})
|
||||
}
|
||||
}, [enableAll]) // Only depend on enableAll, not on enabledMCPs
|
||||
const enableAll = every(activeServers, (server) =>
|
||||
enabledMCPs.some((enabledServer) => enabledServer.name === server.name)
|
||||
)
|
||||
|
||||
const setEnableAll = () => activeServers.forEach((s) => toggelEnableMCP(s))
|
||||
|
||||
const menu = (
|
||||
<div ref={menuRef} className="ant-dropdown-menu">
|
||||
@ -67,7 +59,11 @@ const MCPToolsButton: FC<Props> = ({ enabledMCPs, onEnableMCP, ToolbarButton })
|
||||
)}
|
||||
{server.baseUrl && <div className="server-url">{server.baseUrl}</div>}
|
||||
</div>
|
||||
<Switch size="small" checked={enabledMCPs.includes(server)} onChange={() => onEnableMCP(server)} />
|
||||
<Switch
|
||||
size="small"
|
||||
checked={enabledMCPs.some((s) => s.name === server.name)}
|
||||
onChange={() => toggelEnableMCP(server)}
|
||||
/>
|
||||
</McpServerItems>
|
||||
))
|
||||
) : (
|
||||
|
||||
@ -291,6 +291,7 @@ const MCPSettings: FC = () => {
|
||||
onCancel={handleCancel}
|
||||
onOk={handleSubmit}
|
||||
confirmLoading={loading}
|
||||
maskClosable={false}
|
||||
width={600}>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item
|
||||
|
||||
@ -33,7 +33,7 @@ import {
|
||||
openAIToolsToMcpTool,
|
||||
upsertMCPToolResponse
|
||||
} from '@renderer/utils/mcp-tools'
|
||||
import { takeRight } from 'lodash'
|
||||
import { isString, takeRight } from 'lodash'
|
||||
import OpenAI, { AzureOpenAI } from 'openai'
|
||||
import {
|
||||
ChatCompletionAssistantMessageParam,
|
||||
@ -400,7 +400,9 @@ export default class OpenAIProvider extends BaseProvider {
|
||||
|
||||
reqMessages.push({
|
||||
role: 'tool',
|
||||
content: toolCallResponse.content,
|
||||
content: isString(toolCallResponse.content)
|
||||
? toolCallResponse.content
|
||||
: JSON.stringify(toolCallResponse.content),
|
||||
tool_call_id: toolCall.id
|
||||
} as ChatCompletionToolMessageParam)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user