From 2bceb302e08378e03720b8915649787f22494590 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 5 Nov 2025 15:33:25 +0800 Subject: [PATCH] fix: tool setting related --- .../AgentSettings/ToolingSettings.tsx | 310 +++++++++++------- 1 file changed, 191 insertions(+), 119 deletions(-) diff --git a/src/renderer/src/pages/settings/AgentSettings/ToolingSettings.tsx b/src/renderer/src/pages/settings/AgentSettings/ToolingSettings.tsx index f5e871f28f..bbe50aaec6 100644 --- a/src/renderer/src/pages/settings/AgentSettings/ToolingSettings.tsx +++ b/src/renderer/src/pages/settings/AgentSettings/ToolingSettings.tsx @@ -1,4 +1,3 @@ -import { Alert, Card, CardBody, CardHeader, Chip, Input, Switch } from '@heroui/react' import { permissionModeCards } from '@renderer/config/agent' import { useMCPServers } from '@renderer/hooks/useMCPServers' import useScrollPosition from '@renderer/hooks/useScrollPosition' @@ -13,7 +12,8 @@ import type { UpdateAgentSessionFunction } from '@renderer/types' import { AgentConfigurationSchema } from '@renderer/types' -import { Modal } from 'antd' +import { Modal, Tag } from 'antd' +import { Alert, Card, Input, Switch } from 'antd' import { ShieldAlert, ShieldCheck, Wrench } from 'lucide-react' import type { FC } from 'react' import { useCallback, useMemo, useState } from 'react' @@ -272,47 +272,63 @@ export const ToolingSettings: FC = ({ agentBase, upda const showCaution = card.caution return ( - handleSelectPermissionMode(card.mode)} - className={`border ${ + className={`flex overflow-hidden rounded-lg border ${ isSelected ? 'border-primary' : 'border-default-200' - } ${disabled ? 'opacity-60' : ''}`}> - -
- {t(card.titleKey, card.titleFallback)} - - {t(card.descriptionKey, card.descriptionFallback)} - -
- {disabled ? ( - - {t('common.coming_soon', 'Coming soon')} - - ) : isSelected ? ( - }> - {t('common.selected', 'Selected')} - - ) : null} -
- - {t(card.behaviorKey, card.behaviorFallback)} - {showCaution ? ( -
- - - {t( - 'agent.settings.tooling.permissionMode.bypassPermissions.warning', - 'Use with caution — all tools will run without asking for approval.' - )} - + } ${disabled ? 'opacity-60' : ''}`} + onClick={() => handleSelectPermissionMode(card.mode)}> + +
+ + {t(card.titleKey, card.titleFallback)} + + + {t(card.descriptionKey, card.descriptionFallback)} + +
+ {disabled ? ( + {t('common.coming_soon', 'Coming soon')} + ) : isSelected ? ( + +
+ + {t('common.selected', 'Selected')} +
+
+ ) : null}
- ) : null} -
-
+ } + styles={{ + header: { + paddingLeft: '12px', + paddingRight: '12px', + borderBottom: 'none' + }, + body: { + paddingLeft: '12px', + paddingRight: '12px' + } + }}> +
+ {t(card.behaviorKey, card.behaviorFallback)} + {showCaution ? ( +
+ + + {t( + 'agent.settings.tooling.permissionMode.bypassPermissions.warning', + 'Use with caution — all tools will run without asking for approval.' + )} + +
+ ) : null} +
+ + ) })} @@ -324,23 +340,31 @@ export const ToolingSettings: FC = ({ agentBase, upda
+ {t('agent.settings.tooling.preapproved.warning.title', 'Pre-approved tools run without manual review.')} + + } + description={ + + {t( + 'agent.settings.tooling.preapproved.warning.description', + 'Enable only tools you trust. Mode defaults are highlighted automatically.' + )} + + } /> setSearchTerm(e.target.value)} placeholder={t('agent.settings.tooling.preapproved.search', 'Search tools')} aria-label={t('agent.settings.tooling.preapproved.search', 'Search tools')} className="w-full" + size={'large'} />
{filteredTools.length === 0 ? ( @@ -352,54 +376,71 @@ export const ToolingSettings: FC = ({ agentBase, upda const isAuto = autoToolIds.includes(tool.id) const isApproved = approvedToolIds.includes(tool.id) return ( - - -
- {tool.name} - {tool.description ? ( - {tool.description} - ) : null} -
- {isAuto ? ( - - {t('agent.settings.tooling.preapproved.autoBadge', 'Added by mode')} - - ) : null} - {tool.type === 'mcp' ? ( - - {t('agent.settings.tooling.preapproved.mcpBadge', 'MCP tool')} - - ) : null} - {tool.requirePermissions ? ( - - {t( - 'agent.settings.tooling.preapproved.requiresApproval', - 'Requires approval when disabled' - )} - + +
+ {tool.name} + {tool.description ? ( + + {tool.description} + ) : null} +
+ {isAuto ? ( + + {t('agent.settings.tooling.preapproved.autoBadge', 'Added by mode')} + + ) : null} + {tool.type === 'mcp' ? ( + {t('agent.settings.tooling.preapproved.mcpBadge', 'MCP tool')} + ) : null} + {tool.requirePermissions ? ( + + {t( + 'agent.settings.tooling.preapproved.requiresApproval', + 'Requires approval when disabled' + )} + + ) : null} +
+ handleToggleTool(tool.id, checked)} + />
- handleToggleTool(tool.id, value)} - /> - + } + styles={{ + header: { + paddingLeft: '12px', + paddingRight: '12px', + borderBottom: 'none' + }, + body: { + paddingLeft: '12px', + paddingRight: '12px', + paddingTop: '0px', + paddingBottom: '0px' + } + }}> {isAuto ? ( - +
{t( 'agent.settings.tooling.preapproved.autoDescription', 'This tool is auto-approved by the current permission mode.' )} - +
) : null} ) @@ -427,26 +468,43 @@ export const ToolingSettings: FC = ({ agentBase, upda {availableServers.map((server) => { const isSelected = selectedMcpIds.includes(server.id) return ( - - -
- {server.name} - {server.description ? ( - {server.description} - ) : null} + +
+ {server.name} + {server.description ? ( + {server.description} + ) : null} +
+ handleToggleMcp(server.id, checked)} + />
- handleToggleMcp(server.id, value)} - /> -
-
+ } + styles={{ + header: { + paddingLeft: '12px', + paddingRight: '12px', + borderBottom: 'none' + }, + body: { + paddingLeft: '12px', + paddingRight: '12px', + paddingTop: '0px', + paddingBottom: '0px' + } + }} + /> ) })}
@@ -462,33 +520,47 @@ export const ToolingSettings: FC = ({ agentBase, upda {t('agent.settings.tooling.steps.review.title', 'Step 3 · Review')} - - + +
- + {t('agent.settings.tooling.review.mode', { defaultValue: `Mode: ${selectedMode}`, mode: selectedMode })} - - + + {t('agent.settings.tooling.review.autoTools', { defaultValue: `Auto: ${autoCount}`, count: autoCount })} - - + + {t('agent.settings.tooling.review.customTools', { defaultValue: `Custom: ${customCount}`, count: customCount })} - - + + {t('agent.settings.tooling.review.mcp', { defaultValue: `MCP: ${agentSummary.mcps}`, count: agentSummary.mcps })} - +
{t( @@ -496,7 +568,7 @@ export const ToolingSettings: FC = ({ agentBase, upda 'Changes save automatically. Adjust the steps above any time to fine-tune permissions.' )} - +