mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 16:49:07 +08:00
feat: Support custom registry address when configuring mcp for npm & fix lint error (#7531)
* feat: Support custom registry address when configuring mcp for npm * fix: lint
This commit is contained in:
parent
066aad7fed
commit
17a8f0a724
@ -1519,6 +1519,7 @@
|
||||
"registry": "Package Registry",
|
||||
"registryTooltip": "Choose the registry for package installation to resolve network issues with the default registry.",
|
||||
"registryDefault": "Default",
|
||||
"customRegistryPlaceholder": "Enter private registry URL, e.g.: https://npm.company.com",
|
||||
"not_support": "Model not supported",
|
||||
"user": "User",
|
||||
"system": "System",
|
||||
|
||||
@ -1513,6 +1513,7 @@
|
||||
"registry": "パッケージ管理レジストリ",
|
||||
"registryTooltip": "デフォルトのレジストリでネットワークの問題が発生した場合、パッケージインストールに使用するレジストリを選択してください。",
|
||||
"registryDefault": "デフォルト",
|
||||
"customRegistryPlaceholder": "プライベート倉庫のアドレスを入力してください(例:https://npm.company.com)",
|
||||
"not_support": "モデルはサポートされていません",
|
||||
"user": "ユーザー",
|
||||
"system": "システム",
|
||||
|
||||
@ -1513,6 +1513,7 @@
|
||||
"registry": "Реестр пакетов",
|
||||
"registryTooltip": "Выберите реестр для установки пакетов, если возникают проблемы с сетью при использовании реестра по умолчанию.",
|
||||
"registryDefault": "По умолчанию",
|
||||
"customRegistryPlaceholder": "Введите адрес частного склада, например: https://npm.company.com",
|
||||
"not_support": "Модель не поддерживается",
|
||||
"user": "Пользователь",
|
||||
"system": "Система",
|
||||
|
||||
@ -1519,6 +1519,7 @@
|
||||
"registry": "包管理源",
|
||||
"registryTooltip": "选择用于安装包的源,以解决默认源的网络问题",
|
||||
"registryDefault": "默认",
|
||||
"customRegistryPlaceholder": "请输入私有仓库地址,如: https://npm.company.com",
|
||||
"not_support": "模型不支持",
|
||||
"user": "用户",
|
||||
"system": "系统",
|
||||
|
||||
@ -1516,6 +1516,7 @@
|
||||
"registry": "套件管理源",
|
||||
"registryTooltip": "選擇用於安裝套件的源,以解決預設源的網路問題",
|
||||
"registryDefault": "預設",
|
||||
"customRegistryPlaceholder": "請輸入私有倉庫位址,如: https://npm.company.com",
|
||||
"not_support": "不支援此模型",
|
||||
"user": "用戶",
|
||||
"system": "系統",
|
||||
|
||||
@ -41,7 +41,10 @@ interface Registry {
|
||||
url: string
|
||||
}
|
||||
|
||||
const NpmRegistry: Registry[] = [{ name: '淘宝 NPM Mirror', url: 'https://registry.npmmirror.com' }]
|
||||
const NpmRegistry: Registry[] = [
|
||||
{ name: '淘宝 NPM Mirror', url: 'https://registry.npmmirror.com' },
|
||||
{ name: '自定义', url: 'custom' }
|
||||
]
|
||||
const PipRegistry: Registry[] = [
|
||||
{ name: '清华大学', url: 'https://pypi.tuna.tsinghua.edu.cn/simple' },
|
||||
{ name: '阿里云', url: 'http://mirrors.aliyun.com/pypi/simple/' },
|
||||
@ -86,6 +89,8 @@ const McpSettings: React.FC = () => {
|
||||
const [resources, setResources] = useState<MCPResource[]>([])
|
||||
const [isShowRegistry, setIsShowRegistry] = useState(false)
|
||||
const [registry, setRegistry] = useState<Registry[]>()
|
||||
const [customRegistryUrl, setCustomRegistryUrl] = useState('')
|
||||
const [selectedRegistryType, setSelectedRegistryType] = useState<string>('')
|
||||
|
||||
const [showAdvanced, setShowAdvanced] = useState(false)
|
||||
|
||||
@ -107,15 +112,34 @@ const McpSettings: React.FC = () => {
|
||||
setIsShowRegistry(true)
|
||||
|
||||
// Determine registry type based on command
|
||||
let currentRegistry: Registry[] = []
|
||||
if (server.command.includes('uv') || server.command.includes('uvx')) {
|
||||
currentRegistry = PipRegistry
|
||||
setRegistry(PipRegistry)
|
||||
} else if (
|
||||
server.command.includes('npx') ||
|
||||
server.command.includes('bun') ||
|
||||
server.command.includes('bunx')
|
||||
) {
|
||||
currentRegistry = NpmRegistry
|
||||
setRegistry(NpmRegistry)
|
||||
}
|
||||
|
||||
// Check if the registryUrl is a custom URL (not in the predefined list)
|
||||
const isCustomRegistry =
|
||||
currentRegistry.length > 0 &&
|
||||
!currentRegistry.some((reg) => reg.url === server.registryUrl) &&
|
||||
server.registryUrl !== '' // empty string is default
|
||||
|
||||
if (isCustomRegistry) {
|
||||
// Set custom registry state
|
||||
setSelectedRegistryType('custom')
|
||||
setCustomRegistryUrl(server.registryUrl)
|
||||
} else {
|
||||
// Reset custom registry state for predefined registries
|
||||
setSelectedRegistryType('')
|
||||
setCustomRegistryUrl('')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,6 +318,16 @@ const McpSettings: React.FC = () => {
|
||||
const onSelectRegistry = (url: string) => {
|
||||
const command = form.getFieldValue('command') || ''
|
||||
|
||||
// If custom registry is selected
|
||||
if (url === 'custom') {
|
||||
setSelectedRegistryType('custom')
|
||||
// Don't set the registryUrl yet, wait for user input
|
||||
return
|
||||
}
|
||||
|
||||
setSelectedRegistryType('')
|
||||
setCustomRegistryUrl('')
|
||||
|
||||
// Add new registry env variables
|
||||
if (command.includes('uv') || command.includes('uvx')) {
|
||||
// envs['PIP_INDEX_URL'] = url
|
||||
@ -308,6 +342,12 @@ const McpSettings: React.FC = () => {
|
||||
setIsFormChanged(true)
|
||||
}
|
||||
|
||||
const onCustomRegistryChange = (url: string) => {
|
||||
setCustomRegistryUrl(url)
|
||||
form.setFieldsValue({ registryUrl: url })
|
||||
setIsFormChanged(true)
|
||||
}
|
||||
|
||||
const onDeleteMcpServer = useCallback(
|
||||
async (server: MCPServer) => {
|
||||
try {
|
||||
@ -484,7 +524,8 @@ const McpSettings: React.FC = () => {
|
||||
name="registryUrl"
|
||||
label={t('settings.mcp.registry')}
|
||||
tooltip={t('settings.mcp.registryTooltip')}>
|
||||
<Radio.Group>
|
||||
<Radio.Group
|
||||
value={selectedRegistryType === 'custom' ? 'custom' : form.getFieldValue('registryUrl') || ''}>
|
||||
<Radio
|
||||
key="no-proxy"
|
||||
value=""
|
||||
@ -504,6 +545,17 @@ const McpSettings: React.FC = () => {
|
||||
</Radio>
|
||||
))}
|
||||
</Radio.Group>
|
||||
{selectedRegistryType === 'custom' && (
|
||||
<Input
|
||||
placeholder={t(
|
||||
'settings.mcp.customRegistryPlaceholder',
|
||||
'请输入私有仓库地址,如: https://npm.company.com'
|
||||
)}
|
||||
value={customRegistryUrl}
|
||||
onChange={(e) => onCustomRegistryChange(e.target.value)}
|
||||
style={{ marginTop: 8 }}
|
||||
/>
|
||||
)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user